Repository navigation
test(sentinel): wait for an electable master before the suite starts - #3658
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 56dd263d28
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ]) as Array<string | Buffer>; | ||
|
|
||
| const info: Record<string, string> = {}; | ||
| for (let i = 0; i + 1 < reply.length; i += 2) { |
There was a problem hiding this comment.
With the default RESP3 client, SENTINEL MASTER returns a map, but raw sendCommand() is treated as an array here. A Map has no .length, so this loop never fills info and the poll times out, failing sentinel setup before tests can run. Handle the map reply or force RESP2 for this probe.
AGENTS.md reference: AGENTS.md:L50-L51
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc8496e33f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Evict rejected RUNNING_SENTINELS entries and tear down sentinels, master/replicas, and the temp config dir so a timeout does not poison later suites or leak containers.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00b21c3a89
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Disable reconnects and cap connectTimeout per probe, move temp-dir cleanup off the failure path, and allow 60s for spawn plus electability.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 40f7ec5a17
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| socket: { | ||
| port: sentinel.port, | ||
| reconnectStrategy: false, | ||
| connectTimeout: remainingMs, |
There was a problem hiding this comment.
Bound the Sentinel handshake by the probe deadline
When a Sentinel accepts TCP but stops replying to the client's HELLO/AUTH, await client.connect() waits for the handshake, so the poll never rechecks its deadline or reaches cleanup and the before hook can hang. The added connectTimeout only bounds TCP establishment; it is removed on the TCP connect event, and these handshake commands have no command timeout. Race the whole probe against the remaining deadline and destroy the client on expiry.
Useful? React with 👍 / 👎.
connectTimeout only bounds TCP; race connect + SENTINEL MASTER against the remaining deadline and absorb late destroy rejections.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73493b1084
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // `connectTimeout` only covers TCP; HELLO/AUTH can still hang, so race | ||
| // the whole handshake + SENTINEL MASTER against the deadline. | ||
| const remainingMs = Math.max(1, deadline - Date.now()); | ||
| const client = createClient({ |
There was a problem hiding this comment.
Attach an error listener to the probe client
If a sentinel drops its socket after client.connect() succeeds while SENTINEL MASTER is pending, RedisClient emits the failure as the client's 'error' event. Because this probe has no error listener, EventEmitter throws from the socket callback instead of letting the catch record and retry the failure, so a transient disconnect can fail the sentinel before hook; attach a listener before connecting.
Useful? React with 👍 / 👎.
| } catch { | ||
| // Spawn failed and already cleaned up / was evicted from the map. | ||
| } | ||
| }), |
There was a problem hiding this comment.
After-hook races in-flight spawn cleanup
Low Severity
after() snapshots RUNNING_NODES and removes those containers in parallel with awaiting the in-flight RUNNING_SENTINELS promise. If Mocha’s before timed out during the electability wait, that promise’s failure path also docker rms the same redis nodes. A second docker rm -f fails, so the after hook can throw even though spawn already tried to clean up.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 73493b1. Configure here.
|
This closes signature A as diagnosed in #3650 — nice work. Two things I checked that hold up:
The |
A mid-probe disconnect emits 'error'; without a listener EventEmitter throws outside the catch and can fail the before hook.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit 207efe1. Configure here.
| await Promise.all(nodes.map(({ dockerId }) => dockerRemove(dockerId))); | ||
| } catch { | ||
| // Spawn failed and already cleaned up / was evicted from the map. | ||
| } |
There was a problem hiding this comment.
Cleanup hides sentinel removal failures
Low Severity
The global after hook now wraps both awaiting the spawn promise and dockerRemove in one empty catch. A failed spawn is expected to be ignored, but a successful spawn whose docker rm fails is also swallowed, so leftover sentinel containers are not reported.
Reviewed by Cursor Bugbot for commit 207efe1. Configure here.


Summary
writeFileSyncso the Docker bind-mount cannot race an empty fileSENTINEL MASTERuntil flags matchparseNodeelectability before returning fromspawnRedisSentinelspawnRedisCluster) so overlapping callers share one topologySignature B is covered by test(sentinel): await the reentrant teardown instead of a fixed delay #3651.
Closes Sentinel suite flakes on master: topology stand-up cascade, plus one racy lifecycle test #3650
Test plan
npx mocha -r tsx --exit --timeout 90000 --grep 'should successfully connect to sentinel|client should be authenticated|multi sendCommand' './lib/sentinel/index.spec.ts'— 5 passingNote
Low Risk
Test infrastructure only; improves Docker sentinel setup reliability with no production client or auth changes.
Overview
Fixes flaky sentinel integration tests (#3650) where suites started as soon as Docker containers were up, before any sentinel reported an electable
mymaster, causing cascading failures and shortbeforehook timeouts.spawnRedisSentinelnow mirrors the cluster spawn pattern: it caches an in-flight promise inRUNNING_SENTINELS, pollsSENTINEL MASTERuntil master flags pass the same electability checks asparseNode, and only then resolves. Probes use bounded handshakes viaraceAgainstDeadline, RESP2/3-safe reply parsing viamapLikeToObject, and full teardown (master, replicas, sentinels, temp config) if readiness fails so containers and map entries do not leak.spawnSentinelNodewrites sentinel config with synchronouswriteFileSyncso bind-mountedredis.confis not empty when the container starts. The globalafterhook andtestWithClientSentinelare updated to await sentinel promises and allow a 60sbeforetimeout on slow hosts.Reviewed by Cursor Bugbot for commit 207efe1. Bugbot is set up for automated code reviews on this repo. Configure here.