Skip to content

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

Open
wants to merge 62 commits into
base: master
Choose a base branch
from

Conversation

prestonvasquez
Copy link
Member

@prestonvasquez prestonvasquez commented Oct 14, 2024

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:

@prestonvasquez prestonvasquez marked this pull request as ready for review April 25, 2025 21:36
@prestonvasquez prestonvasquez requested a review from a team as a code owner April 25, 2025 21:36
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAP changes look good to me. Pending Shane's second implementation though.

@prestonvasquez prestonvasquez requested review from a team as code owners July 14, 2025 19:52
@prestonvasquez prestonvasquez requested review from durran, katcharov and JamesKovacs and removed request for a team, durran, katcharov and JamesKovacs July 14, 2025 19:52
@@ -53,8 +53,9 @@ An error is considered retryable if it meets any of the following criteria:
| SocketException | 9001 |

- a [PoolClearedError](../connection-monitoring-and-pooling/connection-monitoring-and-pooling.md#connection-pool-errors)
- Any of the above retryable errors that occur during a connection handshake (including the authentication step). For
example, a network error or ShutdownInProgress error encountered when running the hello or saslContinue commands.
- Any of the above retryable errors that occur during a connection handshake (including the authentication step) or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are drivers without CSOT (currently Rust and C) expected to implement these changes in their retryability behavior as part of this ticket? If so, I think we should add retryability-only tests in this PR or prioritize DRIVERS-3216.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isabelatkinson I think this update would only be relevant to driver that implement CSOT. Otherwise, the only I/O that occurs during checkout is the connection handshake which have tests prescribed in DRIVERS-746.

For context, this ticket introduces I/O to CMAP to both "drain" the TCP buffer and perform aliveness checks for connections pending response data. The pathological case is the aliveness check which will return an error but preserve the connection if successful and so should retry at the operation layer.

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retryability spec changes LGTM. Rust does not have CSOT, so I'm not able to POC/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants