Skip to content

Commit 3521829

Browse files
committed
Asynchronous timeout
1 parent 5a87b91 commit 3521829

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pymongo/pool_shared.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,14 @@ async def _async_create_connection(address: _Address, options: PoolOptions) -> s
242242
timeout = options.connect_timeout
243243
elif timeout <= 0:
244244
raise socket.timeout("timed out")
245-
sock.settimeout(timeout)
246245
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)
247246
_set_keepalive_times(sock)
248247
sock.setblocking(False)
249-
await asyncio.get_running_loop().sock_connect(sock, sa)
248+
await asyncio.wait_for(
249+
asyncio.get_running_loop().sock_connect(sock, sa), timeout=timeout
250+
)
250251
return sock
251-
except OSError as e:
252+
except (OSError, asyncio.TimeoutError) as e:
252253
err = e
253254
sock.close()
254255

0 commit comments

Comments
 (0)