Repository navigation
ci: wait for mongod before initiating the replica set, and initiate again - #799
Open
LeeroyHannigan wants to merge 2 commits into
Open
LeeroyHannigan wants to merge 2 commits into
LeeroyHannigan wants to merge 2 commits into
Conversation
…gain start_mongo in devtools/catalog_checks.py took any mongosh output ending in 1 as an answered ping. A refused connection prints "MongoNetworkError: connect ECONNREFUSED 127.0.0.1:<port>", and every port the five MongoDB check scripts use in CI (27041, 27051, 27061, 27071, 27081) ends in 1, so the wait ended on the first poll whether or not mongod was listening. The one rs.initiate then went to a mongod that was not accepting connections yet, nothing sent it again, and the check failed with "<container> did not become primary". check-mongodb-auth had a copy of the same wait, which did not report a member that never became primary. Both now call initiate_replica_set, which drops the ping. Each poll runs db.hello() and reads only the last line of mongosh's output, which has to be exactly primary, initiated (a configuration, no primary yet) or uninitiated (no setName). rs.initiate is sent after each poll that prints uninitiated, so it goes only to a mongod that answered, and it is sent again after an initiate that returned an error. The 120 polls, with 1 s between them, equal the old ping and primary waits combined. A member that is not primary after them is reported with the last poll's output, the last initiate's output and the end of the container's log. The unit tests cover refused connections before and after the initiate, an initiate that takes no effect, and both failure reports. Each of four bugs put back (the suffix match, a single initiate, an initiate after any poll that is not primary, a report without the poll's output) fails at least two of them. Against mongo:7, start_mongo on 27091 and check-mongodb-auth's keyFile set on 27093 were primary in under 6 s, each after one refused poll and one rs.initiate. Fixes #793
LeeroyHannigan
requested review from
amrith,
c33howard,
eliseong,
hitesh96db,
jcshepherd,
navareamol,
pdf-amzn and
robinnsc
as code owners
November 3, 2026 13:32
Merged
6 of 8 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
devtools/catalog_checks.py: a newinitiate_replica_set(container, port), whichstart_mongonow calls. Each poll runsdb.hello()and reads only the last line of mongosh's output, which has to be exactlyprimary,initiated(a configuration, no primary yet) oruninitiated(nosetName).rs.initiateis sent after each poll that printsuninitiated, so it goes only to a mongod that answered, and it is sent again after an initiate that returned an error. A member that is not primary after 120 polls, with 1 s between them, is reported with the last poll's output, the last initiate's output and the end of the container's log.devtools/check-mongodb-auth:start_with_authcallsinitiate_replica_setin place of its own copy of the ping and primary waits. That copy did not report a member that never became primary; the script went on tocreateUserand failed there.devtools/catalog_checks_test.py: five tests ofinitiate_replica_setagainst a fake mongod.Why
The ping wait added with the MongoDB catalog checks in e0e1068 (#681) took any mongosh output ending in 1 as an answer. A refused connection prints
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:<port>, and every port the MongoDB check scripts use in CI ends in 1 (27041, 27051, 27061, 27071, 27081). The wait ended on the first poll whether or not mongod was listening, the singlers.initiatewent to a mongod that refused the connection, nothing sent it again, and the check failed with<container> did not become primary. With no mongod listening, the old check returned True on ports 27071 and 27041 and False on 27072.The failure appeared on #433 (run 41559159173) and #416 (run 41633014404), and #793 lists #783, #463 and #431.
devtools/run-mongodb-testsis not changed. Its ping wait matches a whole line (grep -q '^1$') on port 27017 inside the container, so this bug does not reach it. It still sends a singlers.initiate.Fixes #793
Testing done
python3 -m unittest discover -s devtools -p '*_test.py' -v: 10 tests pass, 5 of them new. They cover refused connections before and after the initiate, an initiate that takes no effect, a member that is never primary, and a mongod that never answers.catalog_checks.pyfails at least two of the new tests: the suffix match (3 failures), a single initiate before the first poll (4), an initiate after any poll that is not primary (3), and a report without the last poll's output (2).start_mongoon 27091: the poll at 1.2 s printedMongoNetworkError: connect ECONNREFUSED 127.0.0.1:27091, the poll at 2.6 s printeduninitiated, oners.initiatereturned{ ok: 1 }, and the member was primary at 4.6 s.replSetStepDownwithforce: trueon that member, five polls 1 s apart printedinitiated.check-mongodb-auth'sstart_with_authon 27093 (keyFile): one refused poll,uninitiated, oners.initiate, primary at 4.3 s, and both users created through the localhost exception by 5.2 s.cargo test --workspaceandcargo fmt --checkwere not run.Checklist