Skip to content

Auto reconnect server side - #5788

Open
aasoni wants to merge 2 commits into
masterfrom
alessandro/auto-reconnect-server-side
Open

Auto reconnect server side#5788
aasoni wants to merge 2 commits into
masterfrom
alessandro/auto-reconnect-server-side

Conversation

@aasoni

@aasoni aasoni commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description of Changes

Auto-Reconnect: Connection replacement and batch subscribe

Adds the two server-side changes needed for SDK auto-reconnect (proposal 0037).

Connection replacement: a client which reconnects can now send a stable, client-generated session_id query parameter. Each connection still gets its own ConnectionId and its own lifecycle events. The session id only identifies which earlier connection a new one supersedes. When a connection claims a session held by a live connection of the same identity, that connection's actor is stopped and its module-side disconnect lifecycle is awaited before the new connection's client_connected, so a module never observes two live connections for one session, nor the old connection's client_disconnected after the new client_connected.

Batch subscribe: SubscribeBatch and SubscribeBatchApplied register multiple query sets under one subscription-manager lock and evaluate them at a single transaction snapshot. No transaction update can interleave with the responses, so a reconnecting client can replay its subscriptions and reconcile its cache against a consistent snapshot. Per-set errors are reported in the response and the remaining sets still apply.

API and ABI breaking changes

No API breaking change. New V3 websocket protocol message. New clients will not be able to send this to old servers.

Expected complexity level and risk

3 - Primarily because of the changes in module_subscription_actor.rs

Testing

  • Smoketests to test superseded connections

@aasoni
aasoni requested review from gefjon and jsdt August 25, 2026 18:48
@aasoni aasoni changed the title Alessandro/auto reconnect server side Auto reconnect server side Aug 25, 2026
@aasoni
aasoni force-pushed the alessandro/auto-reconnect-server-side branch 5 times, most recently from 9d2f341 to 391006b Compare August 26, 2026 09:39
@aasoni

aasoni commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

The riskiest changes are probably in module_subscription_actor and are the following:

  1. Refactor compile_queries into two functions, hash_queries and compile_hashed_queries
  2. Additionally, compile_hashed_queries can optionally take a tx lock so that batched subscriptions can compile and apply all queries under the same lock

This allows batched subscriptions to hash queries outside of the tx lock and then compile them all under the same lock.
Additionally batched subscriptinos will apply under this same lock.
This is the most correct thing to do, however maybe performance wise not the best, I am not sure. We could alternatively acquire and drop a tx lock for each query set compilation separately. However the behavior for a subscription batch of 10 sets each with 5 queries is no worse then for a single set with 50 queries which is why ultimately the change felt fine to me.

@aasoni
aasoni force-pushed the alessandro/auto-reconnect-server-side branch 2 times, most recently from 3478af8 to 7ba085d Compare August 26, 2026 11:35
Adds the two server-side changes needed for SDK auto-reconnect
(proposal 0037).

Connection replacement: a client which reconnects can now send a stable,
client-generated `session_id` query parameter. Each connection still
gets its own ConnectionId and its own lifecycle events. The session id
only identifies which earlier connection a new one supersedes. When a
connection claims a session held by a live connection of the same
identity, that connection's actor is stopped and its module-side
disconnect lifecycle is awaited before the new connection's client_connected,
so a module never observes two live connections for one session, nor the
old connection's client_disconnected after the new client_connected.

Batch subscribe: SubscribeBatch and SubscribeBatchApplied register
multiple query sets under one subscription-manager lock and evaluate
them at a single transaction snapshot. No transaction update can
interleave with the responses, so a reconnecting client can replay its
subscriptions and reconcile its cache against a consistent snapshot.
Per-set errors are reported in the response and the remaining sets still
apply
@aasoni
aasoni force-pushed the alessandro/auto-reconnect-server-side branch from 7ba085d to 1ce785b Compare August 26, 2026 15:39
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