Coalesce Mongo reconnect recovery - #368
Merged
Merged
Conversation
witbrock
marked this pull request as ready for review
August 12, 2026 08:29
|
|
||
| assert len(results) == 12 | ||
| assert {result["client"] for result in results} == {client} | ||
| assert connect_count == 1 |
| time.sleep(_exponential_backoff(base_ms, attempt_num, max_ms)) | ||
| _execute_reconnect_attempt(reconnect_attempt) | ||
| error = None | ||
| except BaseException as exc: # noqa: BLE001 - release waiting callers |
| build_error: BaseException | None = None | ||
| try: | ||
| candidate, clear_preference_on_failure = _build_real_connection_candidate() | ||
| except BaseException as exc: # noqa: BLE001 - finalise cancellation waves |
| result = call() | ||
| with result_lock: | ||
| results.append(result) | ||
| except BaseException as exc: # noqa: BLE001 - asserted by caller |
| try: | ||
| start.wait(timeout=2) | ||
| results.append(operation()) | ||
| except BaseException as exc: # noqa: BLE001 - asserted by the test thread |
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 changed
Why
A transient Mongo or network failure could cause many concurrent requests and workers to independently invalidate the client, probe routes, and construct new clients. That multiplied a single outage into repeated Atlas handshakes, long request tails, and lease risk.
Impact
Concurrent callers now share one physical recovery attempt at a time. A later independent call can still retry after a failed wave, and stronger degraded-route intent receives one bounded atomic follow-up. Existing direct, DNS fallback, SSH tunnel, writable-primary, replica-set, and invalidate-without-close behaviour is preserved.
Validation
git diff --checkpassed.Residual limitation
A completion retained briefly for a lagging reconnect caller is not tagged with the Mongo generation. An unrelated direct invalidation in that tiny interval could yield a stale success receipt; the subsequent canonical operation detects it, and a fresh reconnect call cannot reuse that completion.
Jira: JVNAUTOSCI-2631