Skip to content

Commit 2d960ac

Browse files
aherlihybehackett
authored andcommitted
PYTHON-968 - Handle EINTR error
1 parent 894775c commit 2d960ac

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pymongo/network.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Internal network layer helper methods."""
1616

1717
import datetime
18+
import errno
1819
import select
1920
import struct
2021

@@ -138,7 +139,17 @@ def receive_message(sock, operation, request_id):
138139
def _receive_data_on_socket(sock, length):
139140
msg = b""
140141
while length:
141-
chunk = sock.recv(length)
142+
try:
143+
chunk = sock.recv(length)
144+
except (IOError, OSError) as exc:
145+
err = None
146+
if hasattr(exc, 'errno'):
147+
err = exc.errno
148+
elif exc.args:
149+
err = exc.args[0]
150+
if err == errno.EINTR:
151+
continue
152+
raise
142153
if chunk == b"":
143154
raise AutoReconnect("connection closed")
144155

0 commit comments

Comments
 (0)