Skip to content

PYTHON-5369 - Re-raise socket.timeout errors if the deadline has alre… #2326

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

Merged
merged 10 commits into from
May 12, 2025
8 changes: 7 additions & 1 deletion pymongo/network_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from pymongo.compression_support import decompress
from pymongo.errors import ProtocolError, _OperationCancelled
from pymongo.message import _UNPACK_REPLY, _OpMsg, _OpReply
from pymongo.pool_options import _is_faas
from pymongo.socket_checker import _errno_from_exception

try:
Expand Down Expand Up @@ -357,7 +358,12 @@ def receive_data(conn: Connection, length: int, deadline: Optional[float]) -> me
except socket.timeout:
if conn.cancel_context.cancelled:
raise _OperationCancelled("operation cancelled") from None
if _PYPY:
if (
_PYPY
or not _is_faas()
and deadline is not None
and deadline - time.monotonic() < 0
):
Copy link
Member

@ShaneHarvey ShaneHarvey May 8, 2025

Choose a reason for hiding this comment

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

I think we want sigstop/sigcont to work the same regardless of what env variables are defined. What if we take an alternative approach here and replace not _is_faas() with not conn.is_sdam? IE only do the extra non-blocking read on SDAM connections.

Will that still fix the flaky tests?

Copy link
Member

Choose a reason for hiding this comment

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

Are the flaky tests still fixed after the is_sdam change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

# We reached the true deadline.
raise
continue
Expand Down
1 change: 1 addition & 0 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,7 @@ async def test_srv_max_hosts_kwarg(self):
)
@unittest.skipIf(sys.platform == "win32", "Windows does not support SIGSTOP")
@async_client_context.require_sync
@mock.patch.dict("os.environ", {"AWS_LAMBDA_RUNTIME_API": "1"})
def test_sigstop_sigcont(self):
test_dir = os.path.dirname(os.path.realpath(__file__))
script = os.path.join(test_dir, "sigstop_sigcont.py")
Expand Down
1 change: 1 addition & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,7 @@ def test_srv_max_hosts_kwarg(self):
)
@unittest.skipIf(sys.platform == "win32", "Windows does not support SIGSTOP")
@client_context.require_sync
@mock.patch.dict("os.environ", {"AWS_LAMBDA_RUNTIME_API": "1"})
def test_sigstop_sigcont(self):
test_dir = os.path.dirname(os.path.realpath(__file__))
script = os.path.join(test_dir, "sigstop_sigcont.py")
Expand Down
Loading