-
Notifications
You must be signed in to change notification settings - Fork 244
DRIVERS-2884 Avoid connection churn when operations timeout #1675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
source/client-side-operations-timeout/tests/connection-churn.yml
Outdated
Show resolved
Hide resolved
source/client-side-operations-timeout/tests/connection-churn.yml
Outdated
Show resolved
Hide resolved
source/client-side-operations-timeout/tests/connection-churn.yml
Outdated
Show resolved
Hide resolved
source/client-side-operations-timeout/tests/connection-churn.yml
Outdated
Show resolved
Hide resolved
source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.md
Outdated
Show resolved
Hide resolved
source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.md
Show resolved
Hide resolved
connectionId: int64; | ||
|
||
/** | ||
* The time it took to complete the pending read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Can we clarify that in the description of duration? We can take inspiration from the definitions of duration for checkout failed
and checkout succeeded
events. Ex:
/**
* The time it took to establish the connection.
* In accordance with the definition of establishment of a connection
* specified by `ConnectionPoolOptions.maxConnecting`,
* it is the time elapsed between emitting a `ConnectionCreatedEvent`
* and emitting this event as part of the same checking out.
*
* Naturally, when establishing a connection is part of checking out,
* this duration is not greater than
* `ConnectionCheckedOutEvent`/`ConnectionCheckOutFailedEvent.duration`.
*
* A driver MAY choose the type idiomatic to the driver.
* If the type chosen does not convey units, e.g., `int64`,
* then the driver MAY include units in the name, e.g., `durationMS`.
*/
duration: Duration;
So, maybe something like:
/**
* The time it took to complete the pending read.
* This duration is defined as the time elapsed between emitting a `PendingResponseStarted` event
* and emitting this event as part of the same checking out.
*
* A driver MAY choose the type idiomatic to the driver.
* If the type chosen does not convey units, e.g., `int64`,
* then the driver MAY include units in the name, e.g., `durationMS`.
*/
duration: Duration;
connectionId: int64; | ||
|
||
/** | ||
* The time it took to complete the pending read. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same comment for other definitions of duration in this PR).
source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.md
Outdated
Show resolved
Hide resolved
source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.md
Outdated
Show resolved
Hide resolved
source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.md
Outdated
Show resolved
Hide resolved
- connectionCheckedInEvent: {} # Second find succeeds. | ||
# If the connection is closed server-side while draining the response, the | ||
# driver must close the connection. | ||
- description: "connection closed server-side while draining response" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a sufficient check that if the awaitPendingResponse
function fails with a non-timeout error the connection should be closed.
source/client-side-operations-timeout/tests/pending-response.yml
Outdated
Show resolved
Hide resolved
@@ -176,6 +176,11 @@ The RetryableWriteError label might be added to an error in a variety of ways: | |||
RetryableWriteError label to that error if the MongoClient performing the operation has the retryWrites | |||
configuration option set to true. | |||
|
|||
- When the driver encounters a network error checking out a connection, it MUST add a RetryableWriteError label to that | |||
error if the MongoClient performing the operation has the retryWrites configuration option set to true. For example, | |||
a network error encountered when checking out a connection that must attempt to discard a pending response from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a network error encountered when checking out a connection that must attempt to discard a pending response
Is this sentence correct? I'm getting tripped up by the "that must attempt". Should it be
a network error encountered when reading a pending response during connection checkout.
- connectionCheckedOutEvent: {} | ||
- connectionCheckedInEvent: {} # Ping finishes. | ||
- connectionCheckedOutEvent: {} | ||
- connectionCheckedInEvent: {} # Insert fails. | ||
- connectionPendingResponseStarted: {} # Pending read fails on first find | ||
- connectionPendingResponseFailed: | ||
reason: error | ||
- connectionClosedEvent: | ||
reason: error | ||
- connectionCheckedOutEvent: {} | ||
- connectionCheckedInEvent: {} # Find finishes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add server selection events to this list (maybe we could use logging tests for this, even though not all drivers have implemented the CLAM spec?)? It would be nice to clarify that the retry happens because the error returned is retryable and we use the existing retry mechanism, not that we retry checkout directly. Basically:
- connectionPendingResponseStarted: {} # Pending read fails on first find
- connectionPendingResponseFailed:
reason: error
- connectionClosedEvent:
reason: error
- serverSelectionStarted
- serverSelectionFinished
- connectionCheckedOutEvent: {}
- connectionCheckedInEvent: {} # Find finishes.
arguments: | ||
filter: {_id: 1} | ||
expectError: | ||
isTimeoutError: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails in Node because isTimeoutError
only applies when timeoutMS
is configured:
isTimeoutError: Optional boolean. If true, the test runner MUST assert that the error represents a timeout due to use of the timeoutMS option. If false, the test runner MUST assert that the error does not represent a timeout.
Maybe splitting hairs here but in Node, we only throw a CSOT timeout error when timeoutMS is enabled for the operation. Because the findOne
doesn't have timeoutMS configured, even though the timeout is caused by a CSOT-enabled command, the findOne
itself doesn't throw a CSOT timeout error.
Zooming out further from just the test runner - what do you think the best solution would be for this situation? Should Node just throw a CSOT timeout error in this circumstance?
This PR implements the design for connection pooling improvements described in DRIVERS-2884, based on the CSOT (Client-Side Operation Timeout) spec. It addresses connection churn caused by network timeouts during operations, especially in environments with low client-side timeouts and high latency.
When a connection is checked out after a network timeout, the driver now attempts to resume and complete reading any pending server response (instead of closing and discarding the connection). This may require multiple checkouts.
Each pending response read is subject to a cumulative 3-second static timeout. The timeout is refreshed after each successful read, acknowledging that progress is being made. If no data is read and the timeout is exceeded, the connection is closed.
To reduce unnecessary latency, if the timeout has expired while the connection was idle in the pool, a non-blocking single-byte read is performed; if no data is available, the connection is closed immediately.
This update introduces new CMAP events and logging messages (PendingResponseStarted, PendingResponseSucceeded, PendingResponseFailed) to improve observability of this path.
Please complete the following before merging:
clusters, and serverless).