Skip to content

fix(mongodb-runner): handle arbiter RS convergence race in metadata check - #770

Merged
addaleax merged 4 commits into
mongodb-js:mainfrom
blink1073:check-arbiter-race-condition
Jun 25, 2026
Merged

fix(mongodb-runner): handle arbiter RS convergence race in metadata check#770
addaleax merged 4 commits into
mongodb-js:mainfrom
blink1073:check-arbiter-race-condition

Conversation

@blink1073

@blink1073 blink1073 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an intermittent failure when starting a replica set with an arbiter. After replSetInitiate, an arbiter node may still be transitioning to ARBITER state when assertAllServersHaveInsertedLocalMetadata() runs, causing a spurious "Arbiter flag mismatch" error. The fix retries the hello check until the member converges (or a timeout is reached), and also handles an ordering edge case in deserialize().

Tracked in https://jira.mongodb.org/browse/DRIVERS-3538.

Open Questions

None.

Checklist

blink1073 added 4 commits June 1, 2026 14:56
…heck

When a replica set is initiated, the code only waits for a PRIMARY to
appear before proceeding to assertAllServersHaveInsertedLocalMetadata().
An arbiter node may still be transitioning to ARBITER state at that
point, so hello.arbiterOnly can be undefined while this.isArbiter is
already true, causing an immediate "Arbiter flag mismatch" throw.

Fix _ensureMatchingMetadataColl to retry via eventually() when isArbiter
is true but hello has not yet confirmed arbiterOnly, giving the member
time to converge. Also handle the deserialize() ordering where isArbiter
is set after _populateBuildInfo runs by skipping the check when
hello.arbiterOnly is true regardless of the local flag.

Add unit tests covering the retry path, immediate-success path, timeout
propagation, and the deserialize ordering edge case.
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 78.727%blink1073:check-arbiter-race-condition into mongodb-js:main. No base build found for mongodb-js:main.

@blink1073
blink1073 requested a review from addaleax June 2, 2026 01:10
@blink1073
blink1073 marked this pull request as ready for review June 2, 2026 01:10
@johnjackweir
johnjackweir removed the request for review from addaleax June 24, 2026 15:01
@addaleax
addaleax merged commit 55f865a into mongodb-js:main Jun 25, 2026
37 of 38 checks passed
@blink1073
blink1073 deleted the check-arbiter-race-condition branch July 1, 2026 01:03
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.

3 participants