Skip to content

fix(rivetkit-core): close attached connections at the sleep grace deadline - #5871

Open
eersnington wants to merge 1 commit into
stack/fix-rivetkit-run-onsleep-after-in-flight-work-kttnpoyxfrom
fix/keep-conns-attached-during-drain
Open

eersnington wants to merge 1 commit into
stack/fix-rivetkit-run-onsleep-after-in-flight-work-kttnpoyxfrom
fix/keep-conns-attached-during-drain

Conversation

@eersnington

@eersnington eersnington commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

#5860 runs the sleep hooks, including connection disconnects, after in-flight work drains. If that work outlives the grace period, connections can still be attached when the grace deadline fires.

  • At the grace deadline, the actor closes every connection that grace closes: all of them on destroy, and the non-hibernatable ones on sleep. It closes the transports directly, because hooks dispatched at the deadline are never awaited.
  • emit_grace_events uses the same closes_on_grace filter, so the hibernation rule lives in one place.
  • Adds a drain test: an action in flight when the runner drains still returns its result to the client.
// rivetkit-rust/packages/rivetkit-core/src/actor/task.rs, on_sleep_grace_deadline
self.ctx
	.disconnect_conns(|conn| closes_on_grace(grace.reason, conn))
	.await

This is part 6 of 6 in a stack:

@claude

claude Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review of #5871

The change is small and targeted, and pulling the hibernation rule into closes_on_grace means emit_grace_events and the deadline path can't drift apart. I read the diff only and did not build or run the tests.

Possible issues

  • Deadline path is not covered by the new test. work sleeps 300ms, which is almost certainly well inside the grace period. The test therefore exercises the drain-then-hooks path from fix(rivetkit): run onSleep after in-flight work and refuse dispatch once it starts #5860, not the new on_sleep_grace_deadline close. Consider a Rust test in rivetkit-core/tests/ or a fixture action that outlives the grace period. It should assert that non-hibernatable connections are closed and hibernatable ones are kept on sleep, and that all are closed on destroy.
  • disconnect_conns(...).await at the deadline. The comment says hooks dispatched at the deadline are never awaited, so this path is already time-critical. Please confirm disconnect_conns cannot block on a slow transport close or user onDisconnect. If it can, bound it with a timeout or run it concurrently with the run_handle abort. A failure is only logged with warn!, which is fine, but a hang would stall teardown.
  • Double cleanup in the new test. startDrainingRuntime registers runtime.cleanup() in onTestFinished, and the test also calls await runtime.cleanup() inline. Confirm cleanup is idempotent.
  • Weak assertion. The test checks only that the action returns "done". It does not check that the connection was then closed with ws.going_away, which the first test does check.

Nits

  • In actor-conn-drain.test.ts, the reflow of output.split(...) looks like an unrelated formatting change.
  • In task.rs, the warn! message follows the logging conventions. It could include the likely cause, per the CLAUDE.md guidance on warning logs.
  • The doc line in sleep-sequence.md is accurate and concise.

Overall this is a reasonable fix. The main gap is test coverage of the deadline close itself.

🤖 Generated with Claude Code

@eersnington
eersnington force-pushed the fix/keep-conns-attached-during-drain branch from e1e8ba2 to 446a13b Compare October 13, 2026 16:56
@eersnington
eersnington added this pull request to stack #5872 October 13, 2026 18:06
@eersnington
eersnington force-pushed the fix/keep-conns-attached-during-drain branch 2 times, most recently from 69f4ec0 to b464654 Compare October 13, 2026 21:10
@eersnington
eersnington removed this pull request from stack #5872 October 13, 2026 21:11
@eersnington
eersnington added this pull request to stack #5875 October 13, 2026 21:11
@eersnington
eersnington force-pushed the fix/keep-conns-attached-during-drain branch from b464654 to 848469a Compare October 13, 2026 21:18
@eersnington
eersnington force-pushed the fix/keep-conns-attached-during-drain branch from 848469a to b7efdf2 Compare October 14, 2026 20:40
@eersnington
eersnington removed this pull request from stack #5875 October 14, 2026 20:40
@eersnington
eersnington changed the base branch from fix/drain-going-away-close-reason to stack/fix-rivetkit-run-onsleep-after-in-flight-work-kttnpoyx October 14, 2026 20:40
@eersnington
eersnington added this pull request to stack #5879 October 14, 2026 20:40
@eersnington eersnington changed the title fix(rivetkit-core): keep connections attached while a draining actor finishes fix(rivetkit-core): close attached connections at the sleep grace deadline Oct 14, 2026

This branch has not been deployed

No deployments
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.

1 participant