Skip to content

[kv] Redis watch stops silently once the subscriber gives up reconnecting #2639

Closed

Description

@rickylabs

Summary

On the Redis KV adapter, a fixed-key watch stops delivering events for good once the subscriber connection has used up its reconnect attempts. No error reaches the caller: the watch iterator just waits forever. An outage of about two seconds is enough.

Evidence (main at b0eb079)

  • packages/kv/adapters/redis/connection.ts:298-301: retryStrategy returns null after IOREDIS_RECONNECT_ATTEMPTS = 5 attempts with delays of 100 to 500 ms. ioredis then ends the connection.
  • packages/kv/adapters/redis/connection.ts:94-97: ensureClient() drops a client whose status === 'end' and reconnects.
  • packages/kv/adapters/redis/connection.ts:127-134: ensureSubscriber() has no such check and keeps returning the ended subscriber.
  • packages/kv/adapters/redis/connection.ts:269: the subscriber's error handler only logs.
  • packages/kv/adapters/redis.adapter.ts:474-539: the watch loop awaits queue.next(…) and has no path that surfaces a dead subscription.
  • Separate from the dead-subscriber case: when the subscriber does reconnect in time, changes published during the gap are lost and the watch does not re-read its keys.

Found by reading the code; not reproduced by running.

Expected behavior

A watch survives a Redis outage: the subscriber is re-established, subscriptions are restored, and the watch re-reads its keys so no change is missed. If recovery is impossible, the iterator fails with a typed error.

Acceptance

  • After the subscriber connection ends, the next reconnect restores existing watches, proven by a test that stops and restarts the Redis server during a watch and fails on current main.
  • After any reconnect, a watch emits the current value of keys that changed during the gap.
  • A watch that cannot be recovered rejects with a typed KV error and does not hang.

Acceptance verified by #2644 (comment).

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions