Repository navigation
fix(queue): bound add_resource poison-message replay and dead-letter it - #5919
Closed
akushonkamen wants to merge 1 commit into
Closed
akushonkamen wants to merge 1 commit into
akushonkamen wants to merge 1 commit into
Conversation
A native parser crash (pdfium.dll BEX64 on Windows) kills the whole server process mid-parse. The interrupted task stays non-terminal and the durable message stays 'processing'; on the next startup RecoverStale resets it to 'pending' with its payload unchanged (crates/ragfs queuefs/backend.rs recover_stale has no delivery counter), so the identical message_id is replayed — and crashes the server again — on every restart. Neither restarting nor deleting the task JSON files clears the loop, and nothing on the Python path counts deliveries: tracker.create() passes through for tasks already stuck in running, and the only bounded requeue covers the lock-handoff path (lock_handoff_retry). Scope: issue Expected #2 (bounded replay + failed marking). Worker-process isolation for parsing (Expected #1) is a separate follow-up. Fix: - Persist a per-task delivery_attempt counter in the task record's meta before any crash-prone work, so a hard death still counts on restart. - After MAX_ADD_RESOURCE_DELIVERY_ATTEMPTS (3) deliveries, dead-letter the message (handler returns failed -> NamedQueue acks it for good), mark the task failed via tracker.fail with an actionable error, release staged artifacts, and log [AddResourceDeadLetter] for operators. Tests (tests/storage/test_add_resource_poison_message.py): - an in-process BaseException crash emulation constructing the processing -> RecoverStale -> re-deliver loop, asserting the parse runs exactly 3 times, the 4th delivery dead-letters (acked) and the task ends failed; red on main (parse ran a 4th time, no ack, task stuck running). - a subprocess test performing real os._exit(1) crash round-trips, same assertions; red on main (4 crashes, never dead-lettered). Fixes volcengine#5879 Signed-off-by: akushonkamen <akushonkamen@163.com>
Collaborator
|
通过修复并发安全修复 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
修复 add_resource 队列 at-least-once 流程中的毒消息无界重投:进程级原生崩溃(Windows 上 pdfium.dll BEX64)会绕过一切 Python 异常路径——没有异常可捕获、没有 finally 可清理——任务卡在 running、消息卡在 processing。Rust 端 RecoverStale 每次启动把同 message_id 无条件翻回 pending 重投,同一份 payload 再次触发崩溃,服务器陷入"启动即崩溃"死循环,重启或删除任务 JSON 文件都无法解除。
Human Involvement
Related Issue
Fixes #5879
Type of Change
Changes Made
根因:
RecoverStale(crates/ragfs/src/plugins/queuefs/backend.rs:495-514)在stale_sec <= 0时无时间闸、也无投递计数,每次启动把同 message_id 无条件翻回 pending 重投。tracker.create对 running 任务直通(add_resource_processor.py:150-178的 terminal 守卫不含 RUNNING);replay_result为 None 即全量重解析(:180-183);唯一有界重排只覆盖锁交接路径(:124-131)。修法(纯 Python 面,不动 Rust 后端):
add_resource_processor._process的 terminal 守卫后读取任务记录 meta 中持久化的delivery_attempt计数——QueueFS 后端没有 in-place 消息更新操作,meta 是随重启存活、且与 message 一一对应的持久账本。tracker.update_stage先持久化自增该计数,进程被硬杀也能在下一次启动时读到。MAX_ADD_RESOURCE_DELIVERY_ATTEMPTS = 3时:清理 staged/prepared 产物、tracker.fail标记任务 failed(含运维可行动的错误信息)、返回ProcessResult.failed使NamedQueue.dequeue无条件 ack(named_queue.py:245-248)永久移除毒消息(死信),并打[AddResourceDeadLetter]日志——服务器从此可在毒消息存在时正常启动。Testing
新增
tests/storage/test_add_resource_poison_message.py(进程内 BaseException 崩溃模拟构造 processing -> RecoverStale -> 重投循环;子进程用例走真实os._exit(1)崩溃往返)。红(main 未修改):
结果:
2 failed。失败原因即无界重投本身:进程内用例assert 4 == 3(第 4 次投递仍重跑崩溃解析、无 ack、任务卡 running),子进程用例assert 4 == 3(4 次真实os._exit(1)崩溃、永不死信)。绿(修复后):
2 passed。timeout 300 python -m pytest tests/storage -q→24 failed / 940 passed / 6 skipped / 84 errors。timeout 600 python -m pytest tests/storage tests/service -q→43 failed / 1315 passed / 6 skipped / 85 errors。与 main 基线(同命令
24F/938P/84E与43F/1313P/85E)的 FAILED+ERROR 清单逐字节 diff 一致(diff 为空):全部失败为环境缺ragfs_pythonRust 绑定的既有问题(ImportError: ragfs_python native library is not available,main 实跑确认),非本次引入;分支净增 2 passed 即新增测试。结果:
All checks passed!/2 files already formatted。Checklist
Screenshots (if applicable)
不适用。
Additional Notes
Scope:本 PR 只覆盖 issue Expected #2(有界重投 + failed 标记)。Expected #1(解析子进程隔离,使原生崩溃不再杀死整个服务器进程)是独立的后续工作,commit message 中已注明 scope。死信后运维可在
[AddResourceDeadLetter]日志定位问题文件,移除或转换该资源后服务器正常服务。