Skip to content

RedisRecordStore re-arm: a failed attempt's .catch can clear a newer memo (microtask race) #428

Closed

Description

@pdettori

Follow-up from #427, P6 on Kubernetes slice 1 (#423). The final review of the RedisRecordStore re-arm fix found this.

Where: harness/src/pool-records.ts, connectOnce. Its .catch clears this.ready unconditionally.

Race:

  1. A re-arm attempt fails. node-redis sets isOpen = false synchronously inside #shouldReconnect, but the rejection takes several microtasks to reach the .catch.
  2. A store call landing in that window takes the !isOpen branch and starts a second connect().
  3. The first .catch then wipes that second memo.
  4. A third caller calls connect() on a socket that is now open and gets Socket already opened.

Impact: the window is microtask-only, and callers retry through timers or I/O, so in practice it is very unlikely. The cost is one failed call until the next retry.

Fix (one line): hold the attempt in a local p, and clear the memo only if this.ready === p. Add a test that interleaves two callers around a failed re-arm.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions