Skip to content

Replication W3: Reconnect/storm control & resource bounds #433

Open

Description

@kriszyp

Workstream W3 of #430 · Foundation · removes the OOM/CPU-spiral class

Status update (2026-07-01)

Partially stale on one detail: subscription-setup retries now have fixed delays in places (scheduled setTimeout retries in subscriptionManager.ts, and a copy-cursor flush-failure backoff landed on the connection side), so "spins with no delay" no longer describes every path. But #327 remains open and the substance stands: there is still no uniform backoff discipline (exponential + jitter + cap) across every layer that can initiate work, and #349 (one-shot intent leaking into a persistent listener) and #288 (per-reconnect TLS context churn) are unchanged. Re-verify #327's exact repro against current main when picking this up.

Summary

Backoff is applied inconsistently across layers, one-shot intents leak into persistent listeners, expensive per-reconnect work amplifies churn into OOM, and oversized payloads are rejected rather than chunked. Together these are the resource-exhaustion bug class under churn.

Root cause / current state

Design direction

  1. One backoff discipline at every layer that can initiate a connection — subscription-setup gets exponential backoff + jitter + cap, mirroring the connection layer; treat ENOTFOUND/connection errors as retryable-with-delay; never spin the main thread.
  2. One-shot intents must not bind to persistent listeners — thread a fromEvent flag so persistent re-fires behave as no-ops.
  3. Memoize createSecureContext keyed on CA material so reconnect churn reuses TLS contexts.
  4. Memory-bounded admission control — back-pressure on bytes/heap outstanding, not just object counts.
  5. Chunk oversized records/payloads through the streaming (blob-style) transport so replication never depends on a single sub-MAX_PAYLOAD message.

Scope

  • Backoff + jitter + cap on subscription-setup; no main-thread spin
  • fromEvent guard so one-shot resubscribe intents don't bind persistent listeners
  • Memoized createSecureContext keyed on CA material
  • Bytes/heap-bounded admission control
  • Chunked transport for oversized records/messages

Retires / advances

Dependencies

Complements W1. Independent enough to start immediately (several are localized, high-ROI fixes — good Phase-1 quick wins).

Effort / risk

M / low–medium.

Acceptance criteria

  • A boot-time DNS failure backs off cleanly (no main-thread spin, bounded log volume).
  • Reconnect churn reuses TLS contexts (flat heap).
  • A record larger than MAX_PAYLOAD replicates via chunking.

🤖 Filed by Claude on behalf of Kris.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:replicationReplication, cluster sync, peer connectionsenhancementNew feature or request

    Type

    Fields

    Priority

    P1

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions