Skip to content

Commit b43f969

Browse files
PYTHON-5492 Fix handling of MaxTimeMSExpired responses (#2477)
(cherry picked from commit 9dbccbe)
1 parent 1c48016 commit b43f969

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

.evergreen/scripts/install-dependencies.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ if ! command -v just &>/dev/null; then
4848
_TARGET="--target x86_64-pc-windows-msvc"
4949
fi
5050
_BIN_DIR=$PYMONGO_BIN_DIR
51+
mkdir -p ${_BIN_DIR}
5152
echo "Installing just..."
5253
mkdir -p "$_BIN_DIR" 2>/dev/null || true
5354
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- $_TARGET --to "$_BIN_DIR" || {
@@ -59,6 +60,7 @@ fi
5960
# Ensure uv is installed.
6061
if ! command -v uv &>/dev/null; then
6162
_BIN_DIR=$PYMONGO_BIN_DIR
63+
mkdir -p ${_BIN_DIR}
6264
echo "Installing uv..."
6365
# On most systems we can install directly.
6466
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="$_BIN_DIR" INSTALLER_NO_MODIFY_PATH=1 sh || {

pymongo/asynchronous/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
_SDAMStatusMessage,
3939
)
4040
from pymongo.message import _convert_exception, _GetMore, _OpMsg, _Query
41+
from pymongo.pool_shared import _get_timeout_details, format_timeout_details
4142
from pymongo.response import PinnedResponse, Response
4243

4344
if TYPE_CHECKING:
@@ -224,6 +225,10 @@ async def run_operation(
224225
if use_cmd:
225226
first = docs[0]
226227
await operation.client._process_response(first, operation.session) # type: ignore[misc, arg-type]
228+
# Append timeout details to MaxTimeMSExpired responses.
229+
if first.get("code") == 50:
230+
timeout_details = _get_timeout_details(conn.opts) # type:ignore[has-type]
231+
first["errmsg"] += format_timeout_details(timeout_details) # type:ignore[index]
227232
_check_command_response(first, conn.max_wire_version)
228233
except Exception as exc:
229234
duration = datetime.now() - start

pymongo/synchronous/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
_SDAMStatusMessage,
3838
)
3939
from pymongo.message import _convert_exception, _GetMore, _OpMsg, _Query
40+
from pymongo.pool_shared import _get_timeout_details, format_timeout_details
4041
from pymongo.response import PinnedResponse, Response
4142
from pymongo.synchronous.helpers import _handle_reauth
4243

@@ -224,6 +225,10 @@ def run_operation(
224225
if use_cmd:
225226
first = docs[0]
226227
operation.client._process_response(first, operation.session) # type: ignore[misc, arg-type]
228+
# Append timeout details to MaxTimeMSExpired responses.
229+
if first.get("code") == 50:
230+
timeout_details = _get_timeout_details(conn.opts) # type:ignore[has-type]
231+
first["errmsg"] += format_timeout_details(timeout_details) # type:ignore[index]
227232
_check_command_response(first, conn.max_wire_version)
228233
except Exception as exc:
229234
duration = datetime.now() - start

test/asynchronous/test_pooling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ async def find_one():
429429
# maxConnecting = unbounded: 30+ connections in ~0.140+ seconds
430430
print(len(pool.conns))
431431

432-
@flaky(reason="PYTHON-5492")
433432
@async_client_context.require_failCommand_appName
434433
async def test_csot_timeout_message(self):
435434
client = await self.async_rs_or_single_client(appName="connectionTimeoutApp")

test/test_pooling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ def find_one():
429429
# maxConnecting = unbounded: 30+ connections in ~0.140+ seconds
430430
print(len(pool.conns))
431431

432-
@flaky(reason="PYTHON-5492")
433432
@client_context.require_failCommand_appName
434433
def test_csot_timeout_message(self):
435434
client = self.rs_or_single_client(appName="connectionTimeoutApp")

0 commit comments

Comments
 (0)