Skip to content

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.

The ConnectionManager handles TCP reconnection with exponential backoff:

  1. 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.
  2. The SDK transitions to Reconnecting state.
  3. Reconnection attempts begin with a 100ms delay, doubling on each failure up to the configured maximum (ReconnectMaxDelayMs, default: 10 seconds).
  4. 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.

When you subscribe, you choose a ReconnectBootstrapMode that controls what happens after reconnection:

await foreach (var change in players.SubscribeAsync(
bootstrap: true,
reconnectMode: ReconnectBootstrapMode.LiveOnly,
ct: ct))
{
// ...
}

On 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))
{
// ...
}

On 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.

The BootstrapState enum tracks the bootstrap status through the full lifecycle, including reconnections:

NotRequested → InProgress → Complete
Complete → RebootstrapInProgress → RebootstrapComplete

The Rebootstrap states let your application distinguish between the initial bootstrap and a reconnection re-bootstrap. They are informational: never drop notifications based on them.

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);
}

EntityMirror 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.

You can trigger a re-bootstrap on demand without waiting for a disconnection:

await sub.RebootstrapAsync();

This 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.

Here is the complete sequence of events during a disconnection and reconnection with ReconnectBootstrapMode.Full:

  1. Connection lost. The SDK transitions to Reconnecting state. Notifications stop arriving.
  2. Reconnection. After exponential backoff, a new TCP connection is established. The SDK sends CONNECT with the original SourceId.
  3. Re-subscription. The SDK iterates all active subscriptions. For subscriptions with Full mode, it sends SUBSCRIBE with bootstrap: true.
  4. BOOTSTRAP_BEGIN. The server begins scanning. BootstrapState transitions to RebootstrapInProgress. The BootstrapStatusChanged event fires.
  5. Bootstrap + live notifications. Bootstrap and live notifications, deletes included, arrive interleaved on the subscription channel. Process them all with version-wins merge, keeping a tombstone for each delete.
  6. BOOTSTRAP_END. Sent once every snapshot row has been delivered. BootstrapState transitions to RebootstrapComplete. The BootstrapStatusChanged event fires. Replace the previous copy with the bootstrap’s set; local state is fully caught up.
  7. Live resumes. Only Created, Updated, and Deleted notifications arrive from this point. No Bootstrap notification follows BOOTSTRAP_END.