Skip to content

sdk: make auto-reconnect backoff configurable via the builder#5527

Open
DexterKoelson wants to merge 1 commit into
clockworklabs:masterfrom
DexterKoelson:feat/reconnect-options
Open

sdk: make auto-reconnect backoff configurable via the builder#5527
DexterKoelson wants to merge 1 commit into
clockworklabs:masterfrom
DexterKoelson:feat/reconnect-options

Conversation

@DexterKoelson

Copy link
Copy Markdown
Contributor

Fixes: #5526

Description of Changes

Add DbConnectionBuilder.withReconnectOptions({ baseDelayMs?, maxDelayMs? }) and a getReconnectOptions() accessor. baseDelayMs is the delay before the first retry (the minimum backoff) and doubles on each consecutive failure up to maxDelayMs. Unset fields keep the current defaults (1000 ms base, 30000 ms max). Invalid values (non-positive, non-finite, or baseDelayMs > maxDelayMs) throw a TypeError.

connectionManagerReconnectDelayMs(attempt, options?) now takes optional overrides, and ConnectionManager.#scheduleReconnect reads them from the retained builder, so the backoff is per connection rather than global. The ReconnectOptions type is exported from the package root.

Applies to connections retained through the ConnectionManager (the React and Solid providers). It has no effect on a connection built and used directly via build(), which does not auto-reconnect.

API and ABI breaking changes

None. withReconnectOptions / getReconnectOptions and the ReconnectOptions type are new, and the extra connectionManagerReconnectDelayMs parameter is optional, so existing callers are unaffected.

Expected complexity level and risk

The change is additive and localized to the builder and the reconnect delay computation. Behavior is unchanged unless withReconnectOptions is called, in which case only the backoff timing differs.

Testing

(Disclaimer: all tests were AI generated)

  • New builder tests in tests/db_connection.test.ts cover storage, single-field overrides, and validation errors.
  • tests/connection_manager_reconnect.test.ts covers the delay function overrides and an end-to-end retained reconnect using custom delays.
  • Existing connection-manager and reconnect suites still pass.

Add DbConnectionBuilder.withReconnectOptions({ baseDelayMs, maxDelayMs }) and a
getReconnectOptions() accessor. connectionManagerReconnectDelayMs now takes
optional overrides, and #scheduleReconnect reads them from the retained
builder, so the exponential backoff is configurable per connection instead of
fixed at the module 1000ms/30000ms constants.

baseDelayMs is the delay before the first retry (the minimum backoff) and
doubles each attempt up to maxDelayMs. Unset fields keep the defaults. Invalid
values (non-positive, non-finite, or base > max) throw. The ReconnectOptions
type is exported from the package root.

Applies to connections retained through the ConnectionManager (the React and
Solid providers); a connection built and used directly does not auto-reconnect.
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.

Make the auto-reconnect backoff configurable in the TypeScript SDK

1 participant