PYTHON-5492 Fix handling of MaxTimeMSExpired responses (#2477)

This commit is contained in:
Steven Silvester 2025-08-15 19:13:51 -05:00 committed by GitHub
parent e44ece0b07
commit 9dbccbee2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 2 deletions

View File

@ -48,6 +48,7 @@ if ! command -v just &>/dev/null; then
_TARGET="--target x86_64-pc-windows-msvc"
fi
_BIN_DIR=$PYMONGO_BIN_DIR
mkdir -p ${_BIN_DIR}
echo "Installing just..."
mkdir -p "$_BIN_DIR" 2>/dev/null || true
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- $_TARGET --to "$_BIN_DIR" || {
@ -59,6 +60,7 @@ fi
# Ensure uv is installed.
if ! command -v uv &>/dev/null; then
_BIN_DIR=$PYMONGO_BIN_DIR
mkdir -p ${_BIN_DIR}
echo "Installing uv..."
# On most systems we can install directly.
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="$_BIN_DIR" INSTALLER_NO_MODIFY_PATH=1 sh || {

View File

@ -38,6 +38,7 @@ from pymongo.logger import (
_SDAMStatusMessage,
)
from pymongo.message import _convert_exception, _GetMore, _OpMsg, _Query
from pymongo.pool_shared import _get_timeout_details, format_timeout_details
from pymongo.response import PinnedResponse, Response
if TYPE_CHECKING:
@ -224,6 +225,10 @@ class Server:
if use_cmd:
first = docs[0]
await operation.client._process_response(first, operation.session) # type: ignore[misc, arg-type]
# Append timeout details to MaxTimeMSExpired responses.
if first.get("code") == 50:
timeout_details = _get_timeout_details(conn.opts) # type:ignore[has-type]
first["errmsg"] += format_timeout_details(timeout_details) # type:ignore[index]
_check_command_response(first, conn.max_wire_version)
except Exception as exc:
duration = datetime.now() - start

View File

@ -37,6 +37,7 @@ from pymongo.logger import (
_SDAMStatusMessage,
)
from pymongo.message import _convert_exception, _GetMore, _OpMsg, _Query
from pymongo.pool_shared import _get_timeout_details, format_timeout_details
from pymongo.response import PinnedResponse, Response
from pymongo.synchronous.helpers import _handle_reauth
@ -224,6 +225,10 @@ class Server:
if use_cmd:
first = docs[0]
operation.client._process_response(first, operation.session) # type: ignore[misc, arg-type]
# Append timeout details to MaxTimeMSExpired responses.
if first.get("code") == 50:
timeout_details = _get_timeout_details(conn.opts) # type:ignore[has-type]
first["errmsg"] += format_timeout_details(timeout_details) # type:ignore[index]
_check_command_response(first, conn.max_wire_version)
except Exception as exc:
duration = datetime.now() - start

View File

@ -429,7 +429,6 @@ class TestPooling(_TestPoolingBase):
# maxConnecting = unbounded: 30+ connections in ~0.140+ seconds
print(len(pool.conns))
@flaky(reason="PYTHON-5492")
@async_client_context.require_failCommand_appName
async def test_csot_timeout_message(self):
client = await self.async_rs_or_single_client(appName="connectionTimeoutApp")

View File

@ -429,7 +429,6 @@ class TestPooling(_TestPoolingBase):
# maxConnecting = unbounded: 30+ connections in ~0.140+ seconds
print(len(pool.conns))
@flaky(reason="PYTHON-5492")
@client_context.require_failCommand_appName
def test_csot_timeout_message(self):
client = self.rs_or_single_client(appName="connectionTimeoutApp")