Skip to content

fix(rivetkit): stop hibernating actor connections by default - #5835

Open
eersnington wants to merge 2 commits into
mainfrom
stack/fix-rivetkit-deliver-events-sent-to-hibernated-connections-before-they-reconnect-utyzksuo
Open

eersnington wants to merge 2 commits into
mainfrom
stack/fix-rivetkit-deliver-events-sent-to-hibernated-connections-before-they-reconnect-utyzksuo

Conversation

@eersnington

@eersnington eersnington commented Oct 5, 2026 •

Copy link
Copy Markdown
Member
  • Actor connections from .connect() (actions and events) now follow canHibernateWebSocket, which defaults to false, instead of always hibernating. can_hibernate in rivetkit-core/src/registry/mod.rs no longer returns true for the actor-connect path. This matches the docs, which already describe WebSocket hibernation as off by default.
  • A connection that does not hibernate closes when its actor sleeps, and the client reconnects. An actor keeps the old behavior by opting in:
actor({
	options: { canHibernateWebSocket: true },
	// ...
});
  • A caller that leaves mid-request no longer keeps the actor awake. When Gateway3 drops the request future, DisconnectOnDrop removes the connection, during onConnect or the action. The action itself still finishes.
  • Driver fixtures that test hibernation now opt in.

This is part 1 of 2 in a stack:

@railway-app

railway-app Bot commented Oct 5, 2026

Copy link
Copy Markdown

This PR was not deployed automatically as @eersnington does not have access to the Railway project.

In order to get automatic PR deploys, please add @eersnington to your workspace on Railway.

@claude

claude Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review

The change is small and the intent is clear. Dropping the is_actor_connect_path shortcut in can_hibernate makes .connect() follow canHibernateWebSocket, which matches the docs. DisconnectOnDrop is a good way to stop an abandoned request from keeping the actor awake. I haven't built the PR or run the tests.

Potential issues

  1. Behavior change for existing actors. Every actor that uses .connect() and relied on hibernation now closes its connections on sleep, and clients reconnect. That is a reasonable fix, but it is user-visible. Call it out in the release notes, and check for other fixtures, examples, or docs that implicitly depend on hibernating connections. Only the fixtures in this diff were updated.
  2. DisconnectOnDrop::drop uses RuntimeSpawner::spawn. If the guard is dropped outside a runtime context, for example during runtime teardown, the spawn could panic on native builds. Probably fine given the actor task context, but it deserves a quick check or a comment.
  3. If the future is dropped mid-emit_connection_open, the spawned disconnect(None) will run disconnect hooks, including onDisconnect, for a connection whose onConnect never completed. Please confirm that is intended, and that disconnect is safe for a connection that was never counted. inc_connections_total only runs after the guard is disarmed.
  4. Minor style: in create_conn, opening.disarm() is called in both the error branch and the success path. Disarm once right after emit_connection_open returns, then branch on the result.

Tests

  • The new no-hibernation test and the two Gateway3 abort tests cover the main paths, and the vi.waitFor calls have justifying comments as required.
  • Nothing covers the DisconnectOnDrop cancellation path on the HTTP action and queue paths in http.rs at the core level. A Rust test under tests/ would help.
  • The abort tests use a fixed waitFor(SLEEP_TIMEOUT + 250). Make sure it isn't flaky in CI, and consider an event-driven wait.

@the-company-company the-company-company Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 2 medium-severity findings

Reviewed commit 061ce65.

Comment thread rivetkit-rust/packages/rivetkit-core/src/actor/connection.rs Outdated
Comment thread rivetkit-rust/packages/rivetkit-core/src/actor/connection.rs Outdated
@eersnington
eersnington force-pushed the stack/fix-rivetkit-deliver-events-sent-to-hibernated-connections-before-they-reconnect-utyzksuo branch 2 times, most recently from 02fd3b3 to df14b27 Compare October 5, 2026 15:22
@eersnington

Copy link
Copy Markdown
Member Author

@claude what can you do if i tag you?

@eersnington eersnington changed the title fix(rivetkit): deliver events sent to hibernated connections before they reconnect fix(rivetkit): stop hibernating actor connections by default Oct 5, 2026
@eersnington
eersnington force-pushed the stack/fix-rivetkit-deliver-events-sent-to-hibernated-connections-before-they-reconnect-utyzksuo branch from df14b27 to 22616c6 Compare October 5, 2026 23:06

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