Repository navigation
Description
Shutdown() stops new ticks. It does not stop the tick already running, and it never claimed to in code — only in its own XML doc, which promised CurrentTickNumber is stable once this returns. That promise is false, and the gap it hides is what this issue is really about.
Originally filed as the leftover half of the June 2026 Test host process crashed investigation. That framing is stale — see What changed below. The remaining defect is a contract that lies, not a thread that needs joining.
The mechanism
Shutdown()(DagScheduler.cs:709-720) signals_workerShutdown, bumps_tickGeneration, joins the workers. Nothing else.- The only thing that stops the timer thread is
StopTimerThread()(HighResolutionTimerServiceBase.cs:201-205, a bounded 2 sJoin), reachable solely throughDispose(bool). - The
_workerShutdowngate inExecuteCallbacks(:396) is at tick entry. A tick already past it runs to completion. _currentTickNumber++is the last statement ofComputeAndRecordTelemetry(DagScheduler.Telemetry.cs:156), itself the last call of both tick paths (:824multi-worker,:868single-worker), on the timer thread.
So CurrentTickNumber can advance by one after Shutdown() returns — and by no more, since _workerShutdown is published before the join.
Why the obvious fix is wrong
OnTickAborted fires at TyphonRuntime.cs:2105, inside OnTickEndInternal — which is the TickEndCallback invoked at DagScheduler.cs:860, six lines before ComputeAndRecordTelemetry. The documented response to that event is FatalStop(), which reaches Shutdown().
So Shutdown() routinely runs on the timer thread, inside the tick it is stopping. On that path the one-tick advance is guaranteed, not merely possible.
The original action item — "have Shutdown() stop + join the timer thread" — would therefore make the timer thread join itself: a guaranteed 2 s stall that returns false and changes nothing, after which the tick completes and increments anyway. The doc fix would not even be delivered by the code fix. This issue anticipated a deadlock risk abstractly; the concrete shipped caller was identified in this report.
What changed since filing
The original body claimed a tick racing view disposal → ViewBase.Contains on a freed HashMap → NullReferenceException. Two parts of that no longer hold:
- The crash is gone. Its amplifier —
ExecuteCallbackshaving no outertry/catchon a raw thread — was fixed in Committed storage discipline (#392) + cluster crash durability (#395) #401. What remains is a logged dropped tick, not a host abort. Regression-locked byDagSchedulerTests.TickThread_UnhandledOrchestrationException_SurfacedNotHostCrash. - The ordering is already correct.
TyphonRuntime.StopInternaldisposes nothing (:363-394), andDispose()joins the timer thread before disposing the per-thread accessors (:397-407→Dispose(bool)→StopTimerThread()). The disposal that raced in June was NUnit fixture teardown, not the runtime's.
The "nothing is running before teardown" property is therefore already held — by Dispose(), one call later. Adding a second quiescence point in Shutdown() would duplicate it, make every existing caller block for up to a tick, and put a thread-affinity branch in a lifecycle method. Declined.
Resolution — state the guarantee honestly
-
Shutdown()doc drops "stable once this returns"; states the at-most-one advance, namesDispose()as the sole quiescence point, and records why the timer thread must not be joined here -
FatalStopdoc: neither it norShutdownis a quiescence point; it typically returns into the tick it is stopping -
OnTickAborteddoc: "after the tick has fully drained" means every system ran or was skipped, not that the tick is over — the handler runs inside the tick and must not block -
DagSchedulerTests.Shutdown_Cleanasserts the advance is in[0, 1]afterShutdown()and0afterDispose(), replacing theThread.Sleep(50)that hid this exact advance behind a settle-then-baseline workaround (added in Fix five timing-dependent test defects that were failing the arm64 nightly #689 afterExpected: 346 But was: 347) - New
StrictTickAbortRuntimeTests.FatalStopFromAbortHandler_ReturnsWithoutSelfJoin_AndCostsExactlyOneMoreTick— callsFatalStop()from insideOnTickAbortedatWorkerCount=1, asserts the counter advances exactly once afterwards, and boundsFatalStop()at 1 s so a future self-join reddens instead of silently costing 2 s - Full engine suite green (5446 passed / 0 failed);
SchedulerLifecycle_RacingShutdownAgainstTick_LeavesNoRunningThread(Stop DagScheduler.Shutdown stranding worker and timer threads that then spin a core forever #690'sSensitiveguard) unaffected
Work sits on branch doc/update-2026-08-15, not yet merged. This issue closes on merge.
Deliberately not done
No lifecycle change. If Shutdown() should ever gain an opt-in quiescence wait, the deliverable is a throw when called from the tick thread — turning the self-join footgun into a diagnosable error — not a join. That would be a new issue with its own justification, not a revival of this one.
Activity
fix: 修复 Lifecycle fatal 测试对 tick 计数收尾时序的错误假设
yhcedpn commentedon Aug 14, 2026
Additional evidence for this issue: a documentation precision gap in
DagScheduler.cs:706.The
Shutdown()doc comment says:That last claim ("stable once this returns") is not accurate: the in-flight tick keeps running on the timer thread after
Shutdown()returns, and its telemetry finalizer (ComputeAndRecordTelemetry->_currentTickNumber++) can land after the return.Shutdown()only joins the worker threads; nothing joins the timer thread untilDispose().Concrete observation from a downstream demo (TyphonRuntime, WorkerCount=1, BaseTickRate=1000, SystemExceptionPolicy=AbortTickAndStop): after
OnTickAbortedfires andFatalStop()(->Shutdown()) returns,CurrentTickNumberintermittently advanced from 0 to 1 — the final bookkeeping of the aborted tick, not a following tick. Isolated runs passed consistently; parallel full-suite runs hit it intermittently. We treat it as a test-side sampling assumption error in our demo, not an engine dispatch/fence bug — consistent with the fix in #689.Suggested cleanup: when
Shutdown()is updated to stop+join the timer thread (per the action above), also amend the doc comment so it no longer promisesCurrentTickNumberis stable immediately upon return — or, short of that, reword it to reflect that the current in-flight tick accounting may still land.fix: 修复 Lifecycle fatal 测试对 tick 计数收尾时序的错误假设
nockawa commentedon Aug 15, 2026
Confirmed, in full — thanks, this is a good catch and the mechanism you describe is exactly right. Verified against the implementation and the tests:
Shutdown()(DagScheduler.cs:709-720) signals_workerShutdown, bumps_tickGeneration, and callsJoinWorkers(). Nothing else.StopTimerThread()(HighResolutionTimerServiceBase.cs:201-205, a bounded 2 sJoin), reachable solely viaDispose(bool)._currentTickNumber++is the last statement ofComputeAndRecordTelemetry(DagScheduler.Telemetry.cs:156), which is the last call of both tick paths (:824multi-worker,:868single-worker), on the timer thread._workerShutdowngate inExecuteCallbacks(:396) is at tick entry, so a tick already past it runs to completion.So the doc's
CurrentTickNumber is stable once this returnsis false, and the other half of the sentence (stops producing ticks) is true.One correction, in your favour: on your path it isn't a race — it's re-entrancy, and it's deterministic.
OnTickAbortedfires atTyphonRuntime.cs:2105, insideOnTickEndInternal, which is theTickEndCallbackinvoked atDagScheduler.cs:860— six lines beforeComputeAndRecordTelemetry. So a handler callingFatalStop()runsShutdown()on the timer thread, inside the tick it is stopping, andShutdown()returns straight back into that tick. The 0→1 advance doesn't merely can happen there; it always does. What was intermittent is your demo's observation racing the timer thread's remaining few lines — so your "test-side sampling assumption error" read is right, and the engine-side statement is stronger than the one you wrote.This also means the action item on this issue can't be implemented as written. "Have
Shutdown()stop + join the timer thread" would, on that path, make the timer thread join itself — a guaranteed 2 s stall that returnsfalseand changes nothing, after which the tick completes and increments anyway. The issue anticipated a deadlock risk abstractly; your report supplies the concrete shipped caller.What is being done
Re-scoping this issue to the contract rather than the join, because the crash it was opened for is gone and the ordering it wanted is already correct:
TyphonRuntime.StopInternaldisposes nothing (:363-394), andDispose()joins the timer thread before disposing the per-thread accessors (:397-407→Dispose(bool)→StopTimerThread()). The "nothing is running before teardown" property is already held — byDispose(), one call later.Adding a second quiescence point in
Shutdown()would duplicate that, make every existingShutdown()caller block for up to a tick, and require a thread-affinity branch in a lifecycle method. Not worth it. Instead, the guarantee gets stated honestly:Shutdown()/FatalStop()stop new ticks; neither is a quiescence point.Dispose()is.CurrentTickNumbermay advance by at most one afterShutdown()returns — exactly one on theOnTickAbortedpath — and by zero afterDispose().OnTickAbortedruns inside the tick; "after the tick has fully drained" meant every system had run or been skipped, not that the tick was over. Handlers must not block.Shutdown(), so the self-join isn't rediscovered later.Two tests pin it, both green:
DagSchedulerTests.Shutdown_Clean— itsThread.Sleep(50)was hiding this exact advance behind a settle-then-baseline workaround (added in Fix five timing-dependent test defects that were failing the arm64 nightly #689 afterExpected: 346 But was: 347). It now asserts the advance is in[0, 1]instead of sleeping past it.StrictTickAbortRuntimeTests.FatalStopFromAbortHandler_ReturnsWithoutSelfJoin_AndCostsExactlyOneMoreTick— new, and the one your report earned: callsFatalStop()from insideOnTickAbortedatWorkerCount=1, asserts the counter advances exactly once afterwards, and boundsFatalStop()at 1 s so a future self-join reddens instead of silently costing 2 s.Full engine suite green (5446 passed / 0 failed).
Your suggested cleanup is therefore taken as the doc half, and declined as the join half — with the reasoning above recorded here so it doesn't get re-proposed.
[-]DagScheduler.Shutdown should stop+join the timer thread before view dispose (teardown race)[/-][+]DagScheduler.Shutdown is not a quiescence point — fix the contract, do not join the timer thread[/+]#404 Shutdown() promised a stable tick number while returning into th…
fix: 修复 Lifecycle fatal 测试对 tick 计数收尾时序的错误假设