Repository navigation
#404 Shutdown() promised a stable tick number while returning into the tick that increments it - #814
Merged
Merged
Conversation
…e tick that increments it DagScheduler.Shutdown's XML doc claimed CurrentTickNumber was stable once it returned. It is not. Shutdown signals _workerShutdown, bumps the generation and joins the workers; the _workerShutdown gate in ExecuteCallbacks is at tick ENTRY, so a tick already past it runs to completion on the timer thread, and _currentTickNumber++ is the last statement of that tick's telemetry finalizer. The counter can therefore advance by one after Shutdown returns, and by no more, since _workerShutdown is published before the join. On the OnTickAborted path the advance is not a race but a certainty. That event fires inside OnTickEndInternal, which is the TickEndCallback invoked six lines before ComputeAndRecordTelemetry, and its documented response is FatalStop. So Shutdown routinely runs on the timer thread, inside the tick it is stopping, and returns straight back into it. This is also why the issue's original action item cannot be implemented as written: joining the timer thread from there is a self-join, which StopTimerThread's two-second bound turns into a stall that returns false and changes nothing. The guarantee is now stated rather than joined for. Shutdown and FatalStop stop new ticks and are not quiescence points; Dispose is, because it joins the timer thread before anything downstream disposes. OnTickAborted's "after the tick has fully drained" meant every system had run or been skipped, not that the tick was over, so the handler is documented as running inside the tick and told not to block. The knowledge already existed in the repository and was sitting in the wrong place. DagSchedulerTests.Shutdown_Clean carried a comment describing this exact mechanism, added by #689 after the assertion failed with "Expected: 346 But was: 347", and then slept fifty milliseconds to hide the advance instead of asserting it. That sleep is now the assertion: at most one advance after Shutdown, none after Dispose. The false doc line came later, from #690, which correctly replaced "waits for the current tick to finish" and introduced "stable once this returns" on the way past. FatalStopFromAbortHandler_ReturnsWithoutSelfJoin_AndCostsExactlyOneMoreTick is new and covers the path the report was filed against: FatalStop called from inside OnTickAborted at WorkerCount 1, asserting the counter advances exactly once afterwards and bounding FatalStop at one second so a future self-join reddens instead of silently costing two.
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.
Fixes #404
DagScheduler.Shutdown's XML doc claimedCurrentTickNumberwas stable once it returned. It is not — and the mechanism was already documented in a test comment 700 lines away, which is how the contradiction survived.Reported externally on #404 (comment); the report is correct, and understates itself.
The defect
Shutdown()signals_workerShutdown, bumps the generation, joins the workers. The_workerShutdowngate inExecuteCallbacks(:396) is at tick entry, so a tick already past it runs to completion on the timer thread — and_currentTickNumber++is the last statement of that tick's telemetry finalizer (DagScheduler.Telemetry.cs:156). The counter can advance by one afterShutdown()returns, and by no more, since_workerShutdownis published before the join.On the
OnTickAbortedpath it is not a race but a certainty. That event fires atTyphonRuntime.cs:2105, insideOnTickEndInternal— which is theTickEndCallbackinvoked atDagScheduler.cs:860, six lines beforeComputeAndRecordTelemetry— and its documented response isFatalStop(). SoShutdown()routinely runs on the timer thread, inside the tick it is stopping, and returns straight back into it.Why the issue's original action item was dropped
"Have
Shutdown()stop + join the timer thread" is a self-join on that path:StopTimerThread's 2 s bound turns it into a stall that returnsfalseand changes nothing, after which the tick completes and increments anyway. The doc fix would not even be delivered by the code fix.The property the issue wanted is already held:
TyphonRuntime.StopInternaldisposes nothing, andDispose()joins the timer thread before disposing the per-thread accessors. #404 has been rewritten to record this.What changed
Docs state the guarantee instead of joining for it —
Shutdown/FatalStopstop new ticks and are not quiescence points,Dispose()is;OnTickAborted's "after the tick has fully drained" means every system ran or was skipped, not that the tick is over, so the handler is documented as running inside the tick and told not to block.Tests:
DagSchedulerTests.Shutdown_Clean— itsThread.Sleep(50)was added by Fix five timing-dependent test defects that were failing the arm64 nightly #689 (afterExpected: 346 But was: 347) to hide this exact advance behind a settle-then-baseline workaround. The sleep is now the assertion: at most one advance afterShutdown(), none afterDispose().StrictTickAbortRuntimeTests.FatalStopFromAbortHandler_ReturnsWithoutSelfJoin_AndCostsExactlyOneMoreTick— new, covering the reported path:FatalStop()from insideOnTickAbortedatWorkerCount=1, asserting the counter advances exactly once, and boundingFatalStop()at 1 s so a future self-join reddens instead of silently costing 2 s.The false line came from #690, which correctly replaced "waits for the current tick to finish" and introduced "stable once this returns" on the way past.
Verification
bash scripts/pre-push.sh— all gate-equivalent checks passed: policy scripts, engine suite Release (5445 passed / 0 failed), Workbench suite Release (662 passed / 0 failed).SchedulerLifecycle_RacingShutdownAgainstTick_LeavesNoRunningThread(#690'sSensitiveguard) unaffected.Not covered locally: shard contention and the serial
Sensitivepass.🤖 Generated with Claude Code
https://claude.ai/code/session_01TmLHw4QbBCE6Cp97xu2w9Y