Skip to content

Commit da04fc8

Browse files
committed
fix waiting logic
1 parent 39b4526 commit da04fc8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pymongo/network_layer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,11 @@ def connection_made(self, transport: BaseTransport) -> None:
500500

501501
async def read(self, bytes_needed: int) -> bytes:
502502
"""Read up to the requested bytes from this connection."""
503+
# Wait for other listeners first.
504+
if len(self._pending_listeners):
505+
await asyncio.gather(*self._pending_listeners)
506+
# If there are bytes ready, then there is no need to wait further.
503507
if self._bytes_ready > 0:
504-
# Wait for other listeners first.
505-
if len(self._pending_listeners):
506-
await asyncio.gather(*self._pending_listeners)
507508
return self._read(bytes_needed)
508509
if self.transport:
509510
try:

0 commit comments

Comments
 (0)