Skip to content

test(sentinel): await the reentrant teardown instead of a fixed delay - #3651

Merged
nkaradzhov merged 1 commit into
redis:masterfrom
Cdineshreddy12:fix/sentinel-lifecycle-flake
Nov 23, 2026
Merged

nkaradzhov merged 1 commit into
redis:masterfrom
Cdineshreddy12:fix/sentinel-lifecycle-flake

Conversation

@Cdineshreddy12

@Cdineshreddy12 Cdineshreddy12 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the signature-B flake from #3650: RedisSentinel lifecycle events › destroy() from an end listener tears down a reentrant reopen failing true !== false on assert.equal(sentinel.isOpen, false).

Root cause (test-only)

The test reopens and tears down from inside the end listener, discards both reentrant promises, then asserts isOpen === false after a fixed setTimeout(100):

sentinel.once('end', () => {
  sentinel.connect().catch(() => { });
  sentinel.destroy().catch(() => { });
});
await sentinel.close();
await setTimeout(100);
assert.equal(sentinel.isOpen, false); // raced

The reentrant connect() runs #setOpen(true) synchronously, so isOpen is true the moment the reopen starts. The reentrant destroy() is what flips it back — but #doDestroy() first awaits the reopen's #connectPromise, i.e. its full topology discovery (the SENTINEL round-trips plus opening the master/replica/pubsub clients, or a 1s backoff in #connect's retry loop). That has no constant upper bound, so under CI load it outlasts the 100ms window and the assert runs while #doDestroy() is still blocked and isOpen is still true.

This is a timing bug in the test, not in the teardown — the final state is correct once destroy() settles. The sibling test just above (tracks a reentrant connect() from an end listener) doesn't flake precisely because it awaits the destroy() promise.

Fix

Capture the reentrant destroy() and await it instead of sleeping:

let reentrantTeardown;
sentinel.once('end', () => {
  sentinel.connect().catch(() => { });
  reentrantTeardown = sentinel.destroy().catch(() => { });
});
await sentinel.close();
await reentrantTeardown;

Awaiting the teardown guarantees #doDestroy() has finished draining the reopen and run its final #setOpen(false) before the asserts, removing the timing dependence entirely. #setReady(true) stays blocked by the #destroy guard throughout, so the ready-before-end ordering assert still holds.

Test-only; no production code touched. Signature A from #3650 (topology stand-up cascade) is separate and not addressed here.


Note

Low Risk
Single test timing fix; no runtime code paths change.

Overview
Fixes a flaky Redis Sentinel lifecycle test (#3650) by awaiting the reentrant destroy() promise instead of sleeping 100ms before assertions.

The test triggers connect() and destroy() from an end listener; teardown must finish the reopen’s in-flight topology work before isOpen becomes false, which under CI load can exceed a fixed delay. Capturing and awaiting reentrantTeardown removes that race while keeping the ready-before-end ordering check.

Test-only — no production changes.

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

The 'destroy() from an end listener tears down a reentrant reopen' test
reopened and tore down from inside the end listener, discarded both
promises, then asserted isOpen === false after setTimeout(100).

destroy() awaits the reentrant connect()'s in-flight topology discovery
before it can finish tearing down, and that discovery is not bounded by
any fixed duration. Under load it outran the 100ms window, so the assert
ran while the reopen's #setOpen(true) still had isOpen true.

Capture the reentrant destroy() and await it, matching the sibling test
above. Removes the timing dependence entirely.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-20T16:31:16.743243Z 5d0bba6 PR opened
ℹ️ 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.

@nkaradzhov
nkaradzhov merged commit f642c77 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.

2 participants