Skip to content

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

Open
blink1073 wants to merge 4 commits into
mongodb-js:mainfrom
blink1073:check-arbiter-race-condition
Open

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

Conversation

@blink1073
Copy link
Copy Markdown
Contributor

@blink1073 blink1073 commented Jun 1, 2026

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.

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