From c22ae84700d7febc569da43708595732d66b8b1f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 Jun 2025 10:47:00 -0500 Subject: [PATCH 1/2] PYTHON-5405 Use legacy wait_for_read cancellation approach on Windows --- pymongo/network_layer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pymongo/network_layer.py b/pymongo/network_layer.py index 6f1bb9a357..e96cf0d081 100644 --- a/pymongo/network_layer.py +++ b/pymongo/network_layer.py @@ -18,6 +18,7 @@ import asyncio import collections import errno +import os import socket import struct import sys @@ -286,6 +287,7 @@ async def _async_socket_receive( _PYPY = "PyPy" in sys.version +_WINDOWS = os.name == "nt" def wait_for_read(conn: Connection, deadline: Optional[float]) -> None: @@ -337,7 +339,8 @@ def receive_data(conn: Connection, length: int, deadline: Optional[float]) -> me while bytes_read < length: try: # Use the legacy wait_for_read cancellation approach on PyPy due to PYTHON-5011. - if _PYPY: + # also use it on Windows due to PYTHON-5405 + if _PYPY or _WINDOWS: wait_for_read(conn, deadline) if _csot.get_timeout() and deadline is not None: conn.set_conn_timeout(max(deadline - time.monotonic(), 0)) @@ -359,6 +362,7 @@ def receive_data(conn: Connection, length: int, deadline: Optional[float]) -> me raise _OperationCancelled("operation cancelled") from None if ( _PYPY + or _WINDOWS or not conn.is_sdam and deadline is not None and deadline - time.monotonic() < 0 From 59d3bf02651c67580bedc408958fbf234623a546 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 Jun 2025 13:25:50 -0500 Subject: [PATCH 2/2] address review --- pymongo/network_layer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pymongo/network_layer.py b/pymongo/network_layer.py index e96cf0d081..78eefc7177 100644 --- a/pymongo/network_layer.py +++ b/pymongo/network_layer.py @@ -18,7 +18,6 @@ import asyncio import collections import errno -import os import socket import struct import sys @@ -287,7 +286,7 @@ async def _async_socket_receive( _PYPY = "PyPy" in sys.version -_WINDOWS = os.name == "nt" +_WINDOWS = sys.platform == "win32" def wait_for_read(conn: Connection, deadline: Optional[float]) -> None: