Skip to content

test(sentinel): wait for an electable master before the suite starts - #3658

Merged
nkaradzhov merged 6 commits into
redis:masterfrom
junaidkhan80121:fix/3650-sentinel-topology-ready
Nov 23, 2026
Merged

nkaradzhov merged 6 commits into
redis:masterfrom
junaidkhan80121:fix/3650-sentinel-topology-ready

Conversation

@junaidkhan80121

@junaidkhan80121 junaidkhan80121 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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 passing

Note

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 short before hook timeouts.

spawnRedisSentinel now mirrors the cluster spawn pattern: it caches an in-flight promise in RUNNING_SENTINELS, polls SENTINEL MASTER until master flags pass the same electability checks as parseNode, and only then resolves. Probes use bounded handshakes via raceAgainstDeadline, RESP2/3-safe reply parsing via mapLikeToObject, and full teardown (master, replicas, sentinels, temp config) if readiness fails so containers and map entries do not leak.

spawnSentinelNode writes sentinel config with synchronous writeFileSync so bind-mounted redis.conf is not empty when the container starts. The global after hook and testWithClientSentinel are updated to await sentinel promises and allow a 60s before timeout on slow hosts.

Reviewed by Cursor Bugbot for commit 207efe1. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T08:37:23.565911Z 73493b1 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/test-utils/lib/dockers.ts Outdated
]) as Array<string | Buffer>;

const info: Record<string, string> = {};
for (let i = 0; i + 1 < reply.length; i += 2) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle the RESP3 map reply

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 👍 / 👎.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/test-utils/lib/dockers.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/test-utils/lib/dockers.ts Resolved
Comment thread packages/test-utils/lib/dockers.ts Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/test-utils/lib/dockers.ts Resolved
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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/test-utils/lib/dockers.ts Resolved

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/test-utils/lib/dockers.ts Resolved
Comment thread packages/test-utils/lib/dockers.ts Resolved
Disable reconnects and cap connectTimeout per probe, move temp-dir
cleanup off the failure path, and allow 60s for spawn plus electability.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

} catch {
// Spawn failed and already cleaned up / was evicted from the map.
}
}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 73493b1. Configure here.

@Cdineshreddy12

Copy link
Copy Markdown
Contributor

This closes signature A as diagnosed in #3650 — nice work. Two things I checked that hold up:

  • The electability gate mirrors the client exactly: parseNode (sentinel/utils.ts:11) rejects a node whose flags include s_down, disconnected, or failover_in_progress, and your poll gates on the same three — so the suite can't start until the sentinel sees the master as electable the same way the client will, which is the crux of the cascade.
  • RUNNING_SENTINELS is evicted on rejection (.catch(… delete …)), so a failed stand-up re-spawns next call instead of caching the failure — the easy thing to miss when moving that map to a promise.

The raceAgainstDeadline late-rejection guard is a nice touch. Reads correct to me from the #3650 side — this is the other half of the flake and lines up with #3651 (the signature-B lifecycle test), so together they should clear the sentinel cascade.

A mid-probe disconnect emits 'error'; without a listener EventEmitter
throws outside the catch and can fail the before hook.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Fix All in Cursor

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.
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 207efe1. Configure here.

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM.

@nkaradzhov
nkaradzhov merged commit 76ebb0b into redis:master Nov 23, 2026
15 checks passed
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.

Sentinel suite flakes on master: topology stand-up cascade, plus one racy lifecycle test

3 participants