Repository navigation
fix(backend): bound the wait for a process drain, not the drain itself - #72
Merged
Merged
Conversation
KillAndDrainAsync waits on three things the daemon does not control: descendant exits, the redirected pipes reaching EOF, and the lifecycle publication tail. A Windows anonymous pipe reaches EOF only when the last inherited copy of its write handle closes anywhere on the machine, and the tail is only as fast as its slowest subscriber. Both callers awaited that with no deadline. InstanceManager.KillInstanceAsync holds the mutation admission and the per-instance gate across the halt, so one wedge queues every later start, stop, kill, remove and settings call on that instance forever, and the halt RPC never returns -- with the client's cancellation token silently ineffective, since KillAndDrainAsync checks it once on entry and every await after that ignores it. Worse, the same drain is on StartAsync's path through DisposeManagedProcessAsync, so a generation that never finishes draining means the instance can never start again until the daemon restarts. The wait is now bounded and the work is not: nothing is cancelled, the drain runs to completion in the background, and the generation is detached on the deadline path as well as on the completion path. Detaching is what fences the straggler, and it is safe there because termination is requested and the terminal status committed synchronously before the drain's first await; every publication path re-checks the current binding, so an abandoned generation cannot reach the catalog however long it takes. A drain that fails rather than outruns us still keeps the binding and rethrows, because then the kill is not known to have taken. ForceKillAndClearAsync and DisposeManagedProcessAsync were near-duplicates of each other; the former is now a wrapper over the latter, so the bound exists in one place. Which of the three waits parks on CI is not established -- two independent traces disagreed and neither had a dump -- which is the argument for bounding the caller rather than any one await. Note the pipe path was already half-bounded: the PTY branch has awaited its pumps with a 2s deadline for some time, while the pipe branch next to it had none. Negative control: with the deadline removed and the rest of the change in place, the new test's halt never returns and it fails on the 5s ceiling at line 969.
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.
Closes #70.
调查过程中 #70 原本的诊断被推翻了,更正已发在该 issue 下;这里只讲结论。
责任方不是 issue 里写的那个
#70 和代码注释都把 14 分钟归给生命周期发布尾部。但测试的
finally在调用ForceKillAndClearAsync之前就已releaseOldTimeout.TrySetResult()——屏障是放开的,执行根本走不到那一步。KillAndDrainAsync(InstanceProcess.cs:319)里有三处外部方可致永不完成::336-337子孙进程退出:344→:602裸await pumpsPumpAsync的读硬编码CancellationToken.None(:460),所以_pumpCancellation.Cancel()无效,:468那个 catch 在此路径是死代码。Windows 匿名管道的 EOF 只在机器上最后一份写句柄副本关闭时到达,包括被无关进程继承的:354发布尾部两次独立追踪对"究竟是哪一处"给出不同倾向,都没有 dump 佐证。 所以本 PR 不猜——在调用方加一次
WaitAsync,一次覆盖三处,diff 也比分别加界更小。冒烟证据:PTY 分支
:590早就给同一危险加了 2 秒上界并带回退,紧邻的管道分支:600-603却是光秃秃的await pumps。一半已经被人加过界了。这是生产缺陷,测试只是信使
InstanceManager.KillInstanceAsync全程持有 mutation admission 和该实例的 gate,一次卡死让该实例之后所有 start/stop/kill/remove/settings 永久排队;halt RPC 不返回;WPF 上是按钮无响应且无报错。StartAsync→DisposeManagedProcessAsync路径上。第 N 代卡住的排空让该实例永远无法再启动,直到 daemon 重启。KillAndDrainAsync只在入口检查一次,之后每个 await 都忽略。修法
与插件能力撤销(
fix(plugins): bound the whole revocation…)同形,但更小——不需要 memoized sweep 字段,因为ResetProcess在超时路径上就清掉绑定。限的是等待,不是工作:不取消任何东西,排空照常在后台跑完。
gate 不变量不被削弱:它从来不是靠"持有 gate 等待"保证的,而是靠 fencing——而 fencing 现在在超时路径上也会发生,此前那条路径是跳过它的。会因半排空实例出错的具体操作是
StartAsync:旧代FinalizeProcessAsync末尾的PublishStoppedAsync()若落在新代已提交Running之后会让目录回退。每条发布路径都会重新检查当前绑定,所以绑定一旦解除,被遗弃的那一代再也够不到目录,无论它还要跑多久。排空失败(而非超时)仍保留绑定并抛出——那时无法确认 kill 是否生效,不能报告虚假的 halt 成功。
顺带把
ForceKillAndClearAsync与DisposeManagedProcessAsync这对近乎重复的方法合并,上界只存在一处。负向对照
去掉
WaitAsync(drainDeadline)、其余改动保留,新测试的halt不返回,在 969 行 5 秒上限处失败:加回上界后通过(2 秒)。测试用一个永不返回的订阅者作为"daemon 无法约束的一方"的替身,确定性触发,不是竞态。
验证
全新重建(先清空全部 obj/bin):整解决方案 0 warning / 0 error;ProtocolTests 1373/1373;Daemon.ApiTests 116/116;
git diff --check干净。不在本 PR 内
InstanceProcessEventPumpTests.cs:986的 3 秒上限。它该调,但单独一个提交,且在这个之后——而且那条测试的Assert.False(haltTask.IsCompleted)(:982)并不能证明它读起来要证明的事:坏运行里haltTask早已停在排空上而非屏障上,放开屏障对它毫无作用。