Skip to content

Wait only on the stopped loop in StopAsync when a restart follows [patch] - #92

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/stopasync-waits-stopped-generation
Oct 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/stopasync-waits-stopped-generation

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #91

What was wrong

StopAsync() captured only the restart pending at the time of the stop. It awaited that restart and only then read PollingTask (and later ActionTask). A Restart()/RestartAsync() requested after the stop is meant to run normally, and it published its new loop as PollingTask outside the lock. When that publish won the race, StopAsync() waited on the new loop, which keeps polling until some later stop, so the returned task never completed. This is the pause-then-resume hang.

Change

  • RestartCoreAsync publishes PollingTask inside the same locked block that checks StopGeneration. The loop body moves to a private PollAsync method with unchanged logic. The CancellationTokenSource is now created after the check, so a cancelled restart creates nothing.
  • StopCore captures PollingTask and ActionTask under the lock, together with the generation bump. A restart that had passed its check has therefore already published the loop that gets captured, and any restart after that publishes nothing. TryRun already refuses to claim a run after a stop, so the captured ActionTask is the last run that loop can start.
  • StopAsync() awaits exactly those two tasks. It no longer awaits the pending restart, which was only there to catch a loop published late, and that can no longer happen.

Verification


Generated by Claude Code

…tch]

StopAsync read PollingTask after the stop, so a Restart() requested
straight afterwards could publish its new loop first, and StopAsync then
waited on that loop, which polls until some later stop. Capture the loop
and run together with the stop, under the lock, and publish a restart's
loop under the same lock as its stop-generation check, so a stop sees
either that loop or none.

Fixes #91

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2nrCvY4DyoEF72Nk1
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StopAsync() can hang forever when RestartAsync()/Restart() is called before it completes (pause → resume): it ends up awaiting the new polling loop

1 participant