Skip to content
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
3 changes: 2 additions & 1 deletion test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
WriteConcernError,
)
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
from pymongo.pool_options import _MAX_METADATA_SIZE, _METADATA, ENV_VAR_K8S, PoolOptions
from pymongo.pool_options import _MAX_METADATA_SIZE, _METADATA, ENV_VAR_K8S, PoolOptions, _is_faas
Copy link
Member

Choose a reason for hiding this comment

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

Need to remove this import

Copy link
Member

Choose a reason for hiding this comment

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

Bump

from pymongo.read_preferences import ReadPreference
from pymongo.server_description import ServerDescription
from pymongo.server_selectors import readable_server_selector, writable_server_selector
Expand Down 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
3 changes: 2 additions & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
WriteConcernError,
)
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
from pymongo.pool_options import _MAX_METADATA_SIZE, _METADATA, ENV_VAR_K8S, PoolOptions
from pymongo.pool_options import _MAX_METADATA_SIZE, _METADATA, ENV_VAR_K8S, PoolOptions, _is_faas
from pymongo.read_preferences import ReadPreference
from pymongo.server_description import ServerDescription
from pymongo.server_selectors import readable_server_selector, writable_server_selector
Expand Down 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