JAVA-5949 preserve connection pool on backpressure errors when establishing connections#1900
Conversation
|
Assigned |
|
Added the following to the description of the PR (a new piece of work to be done within the PR): DRIVERS-3394: adjust spec test description (#1894)(JAVA-6095). |
| // clear the pool as they're not related to overload. | ||
| // TLS configuration errors (certificate validation, protocol mismatches) should also clear the pool | ||
| // as they indicate configuration issues, not server overload. | ||
| if (beforeHandshake && !sdamIssue.relatedToAuth() && !sdamIssue.relatedToTlsConfigurationError()) { |
There was a problem hiding this comment.
Currently we attach SystemOverloadedError and RetryableError labels in the SDAM error-handling path (effectively only for DefaultServer). In load-balanced mode, SDAM isn’t involved: the LB code path invalidates the pool directly (e.g., connectionPool.invalidate(serviceId, generation)), so the labeling logic is bypassed.
This means users running the driver in LB mode (behind an NLB) can still hit network errors, TLS handshake failures, timeouts during connection establishment or hello, but won’t get the labels.
However, these labels are a CMAP requirement, not SDAM. The CMAP spec states: “The pool MUST add the error labels SystemOverloadedError and RetryableError to network errors or network timeouts it encounters during the connection establishment or the hello message.”
Since this is defined as a pool behavior (topology-agnostic), it seems we should implement the labeling in the connection pool layer so it applies consistently in both default and load-balanced modes.
There was a problem hiding this comment.
Pull request overview
This PR updates SDAM/backpressure handling so that connection-establishment failures caused by server-side backpressure do not clear the connection pool, and adds/updates tests and matchers to align with the SDAM spec test expectations.
Changes:
- Adjust SDAM exception handling to avoid invalidating the pool on certain pre-handshake network failures, and add TLS-configuration-error classification.
- Add new error label constants (
SystemOverloadedError,RetryableError) and apply them for backpressure-related failures. - Extend unified event matching for additional server types and add a prose test for connection pool backpressure behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| driver-sync/src/test/functional/com/mongodb/client/unified/EventMatcher.java | Extends server type matching for SDAM serverDescriptionChangedEvent expectations. |
| driver-sync/src/test/functional/com/mongodb/client/ServerDiscoveryAndMonitoringProseTests.java | Adds a prose test intended to validate connection pool backpressure behavior via server rate limiter parameters. |
| driver-core/src/test/unit/com/mongodb/internal/connection/DefaultServerSpecification.groovy | Updates unit tests to expect pool preservation on network errors during connection establishment (sync/async). |
| driver-core/src/main/com/mongodb/internal/connection/SdamServerDescriptionManager.java | Adds TLS configuration error detection helper on SDAM issues. |
| driver-core/src/main/com/mongodb/internal/connection/DefaultSdamServerDescriptionManager.java | Changes SDAM exception handling to preserve pool/server description for certain pre-handshake failures and apply labels. |
| driver-core/src/main/com/mongodb/MongoException.java | Introduces new public error label constants used by the backpressure handling path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
[this comment is left on a file, but has nothing to do with the file; this is done so that we could reply to the comment; commenting on a PR does not allow replies - horrendous GitHub functionality]
The current PR seemingly depends on #1856 (see the description of the current PR). We need to decide what to do with that.
P.S. I originally left my thoughts in the description of this PR, but I don't know if that's what we are going to do.
There was a problem hiding this comment.
We no longer depend on this PR see #1900 (comment)
There was a problem hiding this comment.
[this comment is left on a file, but has nothing to do with the file; this is done so that we could reply to the comment; commenting on a PR does not allow replies - horrendous GitHub functionality]
- Could you please confirm that all the specification changes listed in the "Specification changes" part of the description of the current PR have been addressed in the PR?
- If they have been addressed, let's update the description correspondingly.
There was a problem hiding this comment.
Description updated. All specs are implemented
There was a problem hiding this comment.
[this comment is left on a file, but has nothing to do with the file; this is done so that we could reply to the comment; commenting on a PR does not allow replies - horrendous GitHub functionality]
JAVA-5949 has an old comment, which instructs to re-enable some tests that were previously disabled when we updated the testing/resources/specifications submodule in main. Those tests were not enabled. Let's enable them and make sure they pass.
There was a problem hiding this comment.
This PR no longer depends on #1856. Spec PR mongodb/specifications#1880 rewrote the backpressure-network-*-fail.yml tests to wait on serverDescriptionChangedEvent instead of serverHeartbeatSucceededEvent.
…establishing connections
- Fixing static check analysis
0be0250 to
bce97d4
Compare
…handshake network timeout
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ureErrorLabeler.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
- Add the complementary test to cover the suppress-on-label branch.
…ultServerSpecification.groovy Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ureErrorLabeler.java Co-authored-by: Viacheslav Babanin <frest0512@gmail.com>
…re/preserve_connection_pool
Original PR #1854 accidentally closed, and had no outstanding review comments.
This current PR depends on [JAVA-6033] ServerHeartbeatSucceededEvent is not fired for initial POLL monitoring #1856:Update: This PR no longer depends on [JAVA-6033] ServerHeartbeatSucceededEvent is not fired for initial POLL monitoring #1856. Spec PR DRIVERS-3367: Fix racy backpressure-network-* tests specifications#1880 rewrote the
backpressure-network-*-fail.ymltests to wait onserverDescriptionChangedEventinstead ofserverHeartbeatSucceededEvent.we should merge the latter intomain, then merge this PR inbackpressure, and leave the necessaryTODOcomments in #1918 related to the dependency on #1856.backpressurebranch, rebasebackpressureon top ofmainto include the changes from themain(see Mergemainintobackpressure#1917 (comment) for more context on this process).TODOcomments.Specification changes:
Note that there was a change in the description of one of the tests that belongs to this PR, but I closed the corresponding JAVA-6095 (see this comment): DRIVERS-3394: adjust spec test description (#1894).
JAVA-5949, JAVA-6056, JAVA-5664
AI usage and effectiveness: