Reconnection
The ConvergeDB SDK automatically reconnects on disconnection. This page explains what happens to subscriptions during a disconnection and how to choose the right reconnection strategy.
Automatic reconnection
Section titled “Automatic reconnection”The ConnectionManager handles TCP reconnection with exponential backoff:
- Connection loss is detected (socket close or liveness timeout). The server also closes a connection that falls too far behind on a subscription’s notifications.
- The SDK transitions to
Reconnectingstate. - Reconnection attempts begin with a 100ms delay, doubling on each failure up to the configured maximum (
ReconnectMaxDelayMs, default: 10 seconds). - On successful reconnection, the SDK re-subscribes all active subscriptions.
No application code is needed for reconnection itself. The question is what happens to your subscription state.
ReconnectBootstrapMode
Section titled “ReconnectBootstrapMode”When you subscribe, you choose a ReconnectBootstrapMode that controls what happens after reconnection:
LiveOnly (default)
Section titled “LiveOnly (default)”await foreach (var change in players.SubscribeAsync( bootstrap: true, reconnectMode: ReconnectBootstrapMode.LiveOnly, ct: ct)){ // ...}// Coming soonOn reconnection, the subscription resumes with live notifications only (no bootstrap). Any changes that occurred during the disconnection are lost. The subscriber’s local state may drift from the server’s state.
Use LiveOnly when:
- The subscriber is an ephemeral UI or dashboard that will refresh naturally.
- Missing a few updates during a brief disconnect is acceptable.
- You want the fastest reconnection without the cost of a full re-scan.
await foreach (var change in players.SubscribeAsync( bootstrap: true, reconnectMode: ReconnectBootstrapMode.Full, ct: ct)){ // ...}// Coming soonOn reconnection, the subscription re-subscribes with bootstrap: true. The server sends a complete entity snapshot followed by live notifications, just like the initial subscribe. This guarantees the subscriber’s local state matches the server exactly after reconnection.
Use Full when:
- The subscriber maintains a mirror database or persistent cache that must stay in sync.
- Missing updates is not acceptable (for example, analytics pipelines or replication targets).
- You need a zero-drift guarantee.
BootstrapState lifecycle
Section titled “BootstrapState lifecycle”The BootstrapState enum tracks the bootstrap status through the full lifecycle, including reconnections:
Initial subscribe
Section titled “Initial subscribe”NotRequested → InProgress → CompleteAfter reconnection (with Full mode)
Section titled “After reconnection (with Full mode)”Complete → RebootstrapInProgress → RebootstrapCompleteThe Rebootstrap states let your application distinguish between the initial bootstrap and a reconnection re-bootstrap. They are informational: never drop notifications based on them.
Reacting to bootstrap state changes
Section titled “Reacting to bootstrap state changes”var mirror = new EntityMirror<ulong, Player>(EntityId.ToULong);await foreach (var change in players.SubscribeAsync( bootstrap: true, reconnectMode: ReconnectBootstrapMode.Full, ct: ct)){ switch (change.Type) { case NotificationType.BootstrapBegin: // A bootstrap or re-bootstrap started. Expect Bootstrap rows. break; case NotificationType.BootstrapComplete: // Scan complete. Local state is now fully caught up. break; } mirror.Apply(change);}// Coming soonEntityMirror collects each re-bootstrap into a fresh set while still applying live changes, and swaps it in whole at BootstrapComplete, so entities deleted during the disconnection disappear. Changes from before the reconnect are never compared by version with those after it, since an in-memory server restart resets versions. See Bootstrap.
Manual re-bootstrap
Section titled “Manual re-bootstrap”You can trigger a re-bootstrap on demand without waiting for a disconnection:
await sub.RebootstrapAsync();// Coming soonThis sends an UNSUBSCRIBE followed by a SUBSCRIBE with bootstrap: true. The BootstrapState transitions to RebootstrapInProgress and then RebootstrapComplete.
Use this for periodic reconciliation: subscribe once with ReconnectBootstrapMode.Full, then call RebootstrapAsync() on a timer to periodically verify local state consistency.
Full reconnection flow
Section titled “Full reconnection flow”Here is the complete sequence of events during a disconnection and reconnection with ReconnectBootstrapMode.Full:
- Connection lost. The SDK transitions to
Reconnectingstate. Notifications stop arriving. - Reconnection. After exponential backoff, a new TCP connection is established. The SDK sends CONNECT with the original SourceId.
- Re-subscription. The SDK iterates all active subscriptions. For subscriptions with
Fullmode, it sends SUBSCRIBE withbootstrap: true. - BOOTSTRAP_BEGIN. The server begins scanning.
BootstrapStatetransitions toRebootstrapInProgress. TheBootstrapStatusChangedevent fires. - Bootstrap + live notifications.
Bootstrapand live notifications, deletes included, arrive interleaved on the subscription channel. Process them all with version-wins merge, keeping a tombstone for each delete. - BOOTSTRAP_END. Sent once every snapshot row has been delivered.
BootstrapStatetransitions toRebootstrapComplete. TheBootstrapStatusChangedevent fires. Replace the previous copy with the bootstrap’s set; local state is fully caught up. - Live resumes. Only
Created,Updated, andDeletednotifications arrive from this point. NoBootstrapnotification follows BOOTSTRAP_END.