Repository navigation
Wait for MongoDB single-member primary to accept writes before reporting healthy - #21638
Conversation
…ing healthy A newly elected member reports PRIMARY in replSetGetStatus (myState: 1) before it finishes drain mode and rejects writes with NotWritablePrimary until hello reports isWritablePrimary. Use hello.isWritablePrimary for both initialization and the health check. Fixes #21637 Co-authored-by: Copilot <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21638Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21638" |
Tests selector4 / 100 PR test projects · 2 PR jobs, from 3 changed files. Selected PR test projects (4 / 100)
Selected PR jobs (2)
How these were chosen — grouped by what changed🔧 📦 affected project 🔧 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the MongoDB write-readiness change.
No open issues 🎉
What changed in this PR
Fixes the single-member MongoDB readiness race behind #21637 by waiting until the elected primary accepts writes before reporting healthy. This prevents consumers using WaitFor from starting during the primary’s drain phase.
Changes:
- Initialization and health checks now require
hello.isWritablePrimary, the expected replica-set name, and exactly one host. - Adds regression tests for draining primaries and readiness validation.
- Updates documentation to describe write-ready health semantics.
| File | Description |
|---|---|
| tests/Aspire.Hosting.MongoDB.Tests/SingleMemberReplicaSetTests.cs | Adds draining-primary regression tests and updates readiness cases. |
| src/Aspire.Hosting.MongoDB/README.md | Clarifies that readiness waits for write acceptance. |
| src/Aspire.Hosting.MongoDB/MongoDBSingleMemberReplicaSet.cs | Uses hello to check writable-primary readiness during initialization. |
| src/Aspire.Hosting.MongoDB/MongoDBBuilderExtensions.cs | Applies the readiness predicate to health checks and updates API documentation. |
Review effort: Balanced
|
[automated] Starting paired CI validation of #21638 against its frozen pre-fix source, using the regular |
|
[automated] The reported single-member not-primary failure reproduced once on baseline source and was not observed in 250 fixed-source workload executions. Efficacy remains suggestive, not conclusive; none of the six workflows was wholly green. Audited 2026-11-08. PR #21638 is open, non-draft, at Observed executions, not aggregate workflow conclusionsAll six are completed
Failure events are individual failed test cases, not failed workers; one worker can contain several. All six generic results jobs fail because Separate conclusions
Budget and evidence limitsThe six campaign workflow dispatches occurred on 2026-11-03. The kickoff specified a 250-runners-per-arm cap, but does not establish whether a separate workflow-run limit applied at the time. The six pre-existing runs count toward the current five-workflow-run ceiling, regardless of conclusion, leaving no authority for additional runs. No reruns are recorded. Actual expenditure is 100 baseline plus 250 fixed workload jobs, plus 12 executed setup/results jobs; six CLI-image jobs were skipped. No further dispatch was made during this audit. All six full log archives and all 75 failure artifacts were retrieved. Artifacts contain DCP Live PR comments and reviews show no later validation-result report after the 2026-11-03 kickoff. Paginated reproduction-workflow discovery from 2026-11-03 through 2026-11-08 found only these six matching validation-branch runs; this does not exclude deleted runs or different branch names. -- AnkitAgent |
Sébastien Ros (sebastienros)
left a comment
There was a problem hiding this comment.
LGTM — single-member readiness now waits for MongoDB's writable-primary signal while preserving set-name and single-member checks. The change adds no public API and keeps the existing experimental configuration and connection behavior intact.
Description
Fixes an intermittent
Hosting.MongoDB (ubuntu-latest)failure inSingleMemberReplicaSetFunctionalTests. The first write after the single-member replica set reports healthy fails:Root cause (product)
WithReplicaSet()readiness usedreplSetGetStatus.myState == 1, both inInitializeAndWaitForPrimaryAsyncand in the health check. A newly elected member reports PRIMARY before it leaves drain mode, and it rejects writes withNotWritablePrimaryuntilhello.isWritablePrimaryis true. When the health check landed in that window, the resource reported Healthy and the consumer's first write failed. Apps usingWaitForhit the same race.I reproduced the window locally with
mongo:9.0(--replSet,replSetInitiate, then pollingreplSetGetStatus,helloand an insert). It appeared in 6 of 6 runs:myStatebecame 1 about 300ms beforeisWritablePrimaryturned true. Every insert in that window failed withNotWritablePrimary, and the first successful insert matched the firstisWritablePrimary: trueexactly.Fix
helloand requireisWritablePrimary, the matchingsetNameand exactly one host. The readiness signal is now the server's own write-acceptance flag rather than its election state.Regression coverage
In
SingleMemberReplicaSetTests, a fakeDrainingMemberreports PRIMARY but is not writable for the first Nhelloprobes:InitializationWaitsUntilTheElectedPrimaryAcceptsWrites: initialization keeps probing until the member is writable.HealthIsUnhealthyWhileTheElectedPrimaryIsDraining: the health check is Unhealthy while the member drains and Healthy afterwards.ReadinessRequiresTheSingleMemberWritablePrimary/ReadinessRejectsHelloFromAStandaloneServer: covers thehellopredicate cases.Negative control: with the
isWritablePrimarycheck removed, 3 of these tests fail. With the fix, all 22 pass inSingleMemberReplicaSetTests.Evidence
ci.yml attempt 1, 2026-10-25 → 2026-11-01: across 214 runs with Hosting.MongoDB jobs, 4
Hosting.MongoDB (ubuntu-latest)jobs failed with this signature (1 on main, 3 on unrelated PR branches). Details are in #21637. This is a separate code path from the multi-member family (#20478, #21593, #21594).Fixes #21637
Checklist
🤖 Posted by AspireAgent (AI Agent)