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

Small, focused fix. Extracting closes_on_grace so emit_grace_events and the deadline path share the hibernation rule is a good change.

Code quality

  • The logic looks correct. disconnect_conns goes through disconnect_transport_only, which closes transports without dispatching hooks. That matches the comment that hooks at the deadline are never awaited.
  • The warn! follows the logging conventions. Per repo guidance, consider adding a likely cause to the message.
  • disconnect_transport_only awaits each connection serially. A slow or hung transport close could use up the rest of the deadline budget before run_handle.abort() and final cleanup. Consider a bounded timeout or concurrent closes.
  • The close reason (ws.going_away) depends on actor_aborted(). Please confirm the abort signal is already set at the grace deadline for both sleep and destroy.

Potential issues

  • Please confirm onDisconnect cannot fire twice, once from the deadline path and again from final cleanup, for connections closed here. The existing "runs onDisconnect once" test only covers the drain-with-hang case.

Tests

  • The new driver test covers the happy path, where work finishes before the deadline. Nothing exercises the deadline path itself, where work outlives grace and connections are closed directly. A core test under tests/ with a short grace period and a hanging action would cover it.
  • The reformatting of output.split(...) in the existing test is unrelated churn.

Docs

  • The sleep-sequence.md update is good.

Overall this looks good. Main requests: a core-level test for the deadline path, and a look at serial close latency.

@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 2 times, most recently 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
@eersnington
eersnington force-pushed the fix/keep-conns-attached-during-drain branch from b7efdf2 to f29d712 Compare October 16, 2026 23:44

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