Skip to content

Commit e2437e4

Browse files
committed
Fix exception handling PYTHON-294
Newer tests uncovered some issues with the previous fix.
1 parent b3509fe commit e2437e4

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

pymongo/connection.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -836,18 +836,10 @@ def __receive_data_on_socket(self, length, sock):
836836
try:
837837
chunk = sock.recv(length - len(message))
838838
except:
839-
# Store the exception from sock.recv() in case we throw a new
840-
# exception in this exception-handler.
841-
exc_type, exc_value, exc_traceback = sys.exc_info()
842-
# PYTHON-294: must close socket here, because if it remains open
843-
# after this then the next time we read from it we may get stale
844-
# data from a previous operation.
845-
try:
846-
self.__pool.discard_socket()
847-
except:
848-
pass
849-
raise exc_value
850-
839+
# If recv was interrupted, discard the socket
840+
# and re-raise the exception.
841+
self.__pool.discard_socket()
842+
raise
851843
if chunk == "":
852844
raise ConnectionFailure("connection closed")
853845
message += chunk

0 commit comments

Comments
 (0)