From 088b65374de9d8ea860b5b8a58b12def6ddf62dd Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 15 Aug 2025 15:23:17 -0500 Subject: [PATCH 1/3] PYTHON-5492 Mark csot test as flaky on linux as well --- .evergreen/scripts/install-dependencies.sh | 2 ++ test/asynchronous/test_pooling.py | 2 +- test/test_pooling.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.evergreen/scripts/install-dependencies.sh b/.evergreen/scripts/install-dependencies.sh index 5425d10c8c..49fc614ca7 100755 --- a/.evergreen/scripts/install-dependencies.sh +++ b/.evergreen/scripts/install-dependencies.sh @@ -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 || { diff --git a/test/asynchronous/test_pooling.py b/test/asynchronous/test_pooling.py index cbf6d336bd..9fa9e79287 100644 --- a/test/asynchronous/test_pooling.py +++ b/test/asynchronous/test_pooling.py @@ -429,7 +429,7 @@ async def find_one(): # maxConnecting = unbounded: 30+ connections in ~0.140+ seconds print(len(pool.conns)) - @flaky(reason="PYTHON-5492") + @flaky(reason="PYTHON-5492", affects_cpython_linux=True) @async_client_context.require_failCommand_appName async def test_csot_timeout_message(self): client = await self.async_rs_or_single_client(appName="connectionTimeoutApp") diff --git a/test/test_pooling.py b/test/test_pooling.py index 5ce4284e33..53402e129b 100644 --- a/test/test_pooling.py +++ b/test/test_pooling.py @@ -429,7 +429,7 @@ def find_one(): # maxConnecting = unbounded: 30+ connections in ~0.140+ seconds print(len(pool.conns)) - @flaky(reason="PYTHON-5492") + @flaky(reason="PYTHON-5492", affects_cpython_linux=True) @client_context.require_failCommand_appName def test_csot_timeout_message(self): client = self.rs_or_single_client(appName="connectionTimeoutApp") From 0696cf88c492e64bc52c42768697955c091740d1 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 15 Aug 2025 17:49:40 -0500 Subject: [PATCH 2/3] append details to MaxTimeMSExpired responses --- pymongo/asynchronous/server.py | 5 +++++ pymongo/synchronous/server.py | 5 +++++ test/asynchronous/test_pooling.py | 1 - test/test_pooling.py | 1 - 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/server.py b/pymongo/asynchronous/server.py index 0f8565f6cc..f21c86a9fd 100644 --- a/pymongo/asynchronous/server.py +++ b/pymongo/asynchronous/server.py @@ -38,6 +38,7 @@ _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 @@ async def run_operation( 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) + first["errmsg"] += format_timeout_details(timeout_details) _check_command_response(first, conn.max_wire_version) except Exception as exc: duration = datetime.now() - start diff --git a/pymongo/synchronous/server.py b/pymongo/synchronous/server.py index a85f1b0db7..bf02ea5c48 100644 --- a/pymongo/synchronous/server.py +++ b/pymongo/synchronous/server.py @@ -37,6 +37,7 @@ _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 @@ def run_operation( 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) + first["errmsg"] += format_timeout_details(timeout_details) _check_command_response(first, conn.max_wire_version) except Exception as exc: duration = datetime.now() - start diff --git a/test/asynchronous/test_pooling.py b/test/asynchronous/test_pooling.py index 9fa9e79287..3193d9e3d5 100644 --- a/test/asynchronous/test_pooling.py +++ b/test/asynchronous/test_pooling.py @@ -429,7 +429,6 @@ async def find_one(): # maxConnecting = unbounded: 30+ connections in ~0.140+ seconds print(len(pool.conns)) - @flaky(reason="PYTHON-5492", affects_cpython_linux=True) @async_client_context.require_failCommand_appName async def test_csot_timeout_message(self): client = await self.async_rs_or_single_client(appName="connectionTimeoutApp") diff --git a/test/test_pooling.py b/test/test_pooling.py index 53402e129b..cb5b206996 100644 --- a/test/test_pooling.py +++ b/test/test_pooling.py @@ -429,7 +429,6 @@ def find_one(): # maxConnecting = unbounded: 30+ connections in ~0.140+ seconds print(len(pool.conns)) - @flaky(reason="PYTHON-5492", affects_cpython_linux=True) @client_context.require_failCommand_appName def test_csot_timeout_message(self): client = self.rs_or_single_client(appName="connectionTimeoutApp") From 80cd8fbc2b4aaadaf2932aed6a361ecc12b3567a Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 15 Aug 2025 17:54:51 -0500 Subject: [PATCH 3/3] typing --- pymongo/asynchronous/server.py | 4 ++-- pymongo/synchronous/server.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pymongo/asynchronous/server.py b/pymongo/asynchronous/server.py index f21c86a9fd..cef8bd011c 100644 --- a/pymongo/asynchronous/server.py +++ b/pymongo/asynchronous/server.py @@ -227,8 +227,8 @@ async def run_operation( 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) - first["errmsg"] += format_timeout_details(timeout_details) + 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 diff --git a/pymongo/synchronous/server.py b/pymongo/synchronous/server.py index bf02ea5c48..6651f63a30 100644 --- a/pymongo/synchronous/server.py +++ b/pymongo/synchronous/server.py @@ -227,8 +227,8 @@ def run_operation( 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) - first["errmsg"] += format_timeout_details(timeout_details) + 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