Repository navigation
fix(sentinel): emit error when the resolved master is unreachable - #3329
GiHoon1123 wants to merge 1 commit into
Conversation
RedisSentinelInternal#connect()'s retry loop only console.log'd a connection failure to the resolved master on every retry attempt, giving applications no way to observe or react to it programmatically. Since sentinel discovery itself can succeed while the master address it resolves to is unreachable (e.g. TLS misconfiguration, a firewalled or NATed address), this could look like a silent hang for up to maxCommandRediscovers (16, ~16s) retries before connect() finally rejects. Emit 'error' instead, matching the existing convention already used elsewhere in this same class (observe()'s per-sentinel failures, PubSubProxy errors) - the "no valid master node" case remains excluded since it's a routine, expected transient during normal failover, not a real failure. Fixes: #3066
|
Thanks for digging into #3066 and adding a regression test. Unfortunately, this change doesn't reach the reported scenario. In #3066 the master clients are created with the default The test also wouldn't pass: with Also note: an unguarded The real fix for #3066 is making initial master connection failure observable to |
Description
Fixes #3066.
RedisSentinelInternal#connect()'s retry loop discovers the current master via the Sentinel nodes (observe()/analyze()), then connects a client to it (transform()). If sentinel discovery succeeds but the resolved master address is actually unreachable (e.g. a TLS misconfiguration, or a firewalled/NATed address — the exact scenario in #3066), the failure was only everconsole.log'd on every retry attempt, with nothing an application could observe, catch, or react to. Since the retry loop waits 1s between attempts and only gives up (rejectingconnect()) aftermaxCommandRediscovers(default 16) attempts, this can look like a ~16 second silent hang with zero visibility into why.The fix is a single line: emit
'error'instead ofconsole.log-ing it. This matches the existing convention already used elsewhere in the same class —observe()already emits'error'for a sentinel node it can't reach, and thePubSubProxywiring does the same — so this isn't a new pattern, just applying the existing one to a path that had been missed. The'no valid master node'case remains excluded from emission, unchanged from before: that message is a normal, expected transient during a real failover (the old master is briefly flagged down before a replica is promoted), not something worth surfacing as an error.RedisSentinel's constructor already wiresthis.#internal.on('error', err => this.emit('error', err))beforeconnect()can ever run, so this emission is guaranteed to have a listener and won't crash on an unhandled'error'event.A regression test was added (
emits error while retrying an unreachable master) usingnodeAddressMapto remap only the resolved master to an unreachable address, so sentinel discovery itself stays healthy the whole time — matching the reported scenario without needing a real TLS setup. It asserts an'error'event fires during the retry loop instead of the connect attempt going silent.Local verification note: I was not able to get the full docker-based sentinel test suite running end-to-end in my local environment to watch this specific new test go green (an environment issue on my end — an existing, unmodified sentinel test hits the same
beforeEachtimeout, so it's unrelated to this change). I did verify:tsc --buildis clean, lint is clean, and the existing docker-free sentinel unit tests (commandOptionssuite) still pass. The new test's control-flow was traced by hand againstdestroy()'s teardown behavior to confirm it won't hang or leave dangling state, but I'd appreciate CI (or a maintainer) confirming it actually passes.Checklist
npm testpass with this change (including linting)? — lint andtsc --buildare clean; the docker-free sentinel unit tests pass; the full docker-based suite (including the new test) could not be run end-to-end locally (see note above) and needs CI to confirm.'error'is an existing, documented event onRedisSentinel.Note
Low Risk
Observability-only change on an existing
errorevent path; connect still fails after the same retry limit, with slightly noisier error events during retries.Overview
When Sentinel finds a master but connecting to that address fails,
RedisSentinelInternal#connect()no longer onlyconsole.logs each retry—itemit('error', err)on every attempt (still skipping the expected transientno valid master nodemessage during failover).That surfaces failures such as TLS or NAT/firewall mismatches (#3066) while
connect()keeps retrying up tomaxCommandRediscovers, instead of a long silent wait. Errors propagate through the existingRedisSentinelinternal → publicerrorwiring.A docker-based regression test uses
nodeAddressMapto point the resolved master at an unreachable port while Sentinels stay healthy, and asserts anerrorevent duringconnect().Reviewed by Cursor Bugbot for commit e6df6a2. Bugbot is set up for automated code reviews on this repo. Configure here.