Skip to content

Commit c7a4ba2

Browse files
committed
PYTHON-4324 Fix NetworkingInterface.gettimeout
1 parent 69bcb4e commit c7a4ba2

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

pymongo/asynchronous/pool.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,22 @@ async def complete_pending(self) -> None:
203203
if not self.pending_response:
204204
return
205205

206-
timeout = self.conn.gettimeout
207206
if _csot.get_timeout():
208207
deadline = min(_csot.get_deadline(), self.pending_deadline)
209-
elif timeout is not None:
210-
deadline = min(time.monotonic() + timeout, self.pending_deadline)
211208
else:
212-
deadline = self.pending_deadline
209+
timeout = self.conn.gettimeout
210+
if timeout is not None:
211+
deadline = min(time.monotonic() + timeout, self.pending_deadline)
212+
else:
213+
deadline = self.pending_deadline
213214

214215
if not _IS_SYNC:
215216
# In async the reader task reads the whole message at once.
216217
# TODO: respect deadline
217218
await self.receive_message(None, True)
218219
else:
219220
try:
220-
network_layer.receive_data(self, self.pending_bytes, deadline) # type:ignore[call-arg]
221+
network_layer.receive_data(self, self.pending_bytes, deadline) # type:ignore[arg-type]
221222
except BaseException as error:
222223
await self._raise_connection_failure(error)
223224
self.pending_response = False

pymongo/network_layer.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def receive_data(
338338
# When the timeout has expired we perform one final non-blocking recv.
339339
# This helps avoid spurious timeouts when the response is actually already
340340
# buffered on the client.
341-
orig_timeout = conn.conn.gettimeout()
341+
orig_timeout = conn.conn.gettimeout
342342
try:
343343
while bytes_read < length:
344344
try:
@@ -444,6 +444,7 @@ class NetworkingInterface(NetworkingInterfaceBase):
444444
def __init__(self, conn: Union[socket.socket, _sslConn]):
445445
super().__init__(conn)
446446

447+
@property
447448
def gettimeout(self) -> float | None:
448449
return self.conn.gettimeout()
449450

@@ -758,7 +759,7 @@ def receive_message(
758759
if _csot.get_timeout():
759760
deadline = _csot.get_deadline()
760761
else:
761-
timeout = conn.conn.gettimeout()
762+
timeout = conn.conn.gettimeout
762763
if timeout:
763764
deadline = time.monotonic() + timeout
764765
else:

pymongo/synchronous/pool.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,22 @@ def complete_pending(self) -> None:
203203
if not self.pending_response:
204204
return
205205

206-
timeout = self.conn.gettimeout
207206
if _csot.get_timeout():
208207
deadline = min(_csot.get_deadline(), self.pending_deadline)
209-
elif timeout is not None:
210-
deadline = min(time.monotonic() + timeout, self.pending_deadline)
211208
else:
212-
deadline = self.pending_deadline
209+
timeout = self.conn.gettimeout
210+
if timeout is not None:
211+
deadline = min(time.monotonic() + timeout, self.pending_deadline)
212+
else:
213+
deadline = self.pending_deadline
213214

214215
if not _IS_SYNC:
215216
# In async the reader task reads the whole message at once.
216217
# TODO: respect deadline
217218
self.receive_message(None, True)
218219
else:
219220
try:
220-
network_layer.receive_data(self, self.pending_bytes, deadline) # type:ignore[call-arg]
221+
network_layer.receive_data(self, self.pending_bytes, deadline) # type:ignore[arg-type]
221222
except BaseException as error:
222223
self._raise_connection_failure(error)
223224
self.pending_response = False

0 commit comments

Comments
 (0)