Skip to content

Commit eeef917

Browse files
author
A. Jesse Jiryu Davis
committed
Fix connection leak in mod_wsgi 2.x and Python <= 2.6: Instead of storing SocketInfos in threadlocals, watch for thread death with a weakref callback to a generic threadlocal PYTHON-353
1 parent 58b3d64 commit eeef917

File tree

10 files changed

+509
-215
lines changed

10 files changed

+509
-215
lines changed

pymongo/connection.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def _send_message(self, message, with_last_error=False):
741741
sock_info)
742742
rv = self.__check_response_to_last_error(response)
743743

744-
self.__pool.return_socket(sock_info)
744+
self.__pool.maybe_return_socket(sock_info)
745745
return rv
746746
except (ConnectionFailure, socket.error), e:
747747
self.disconnect()
@@ -758,8 +758,7 @@ def __receive_data_on_socket(self, length, sock_info):
758758
try:
759759
chunk = sock_info.sock.recv(length)
760760
except:
761-
# If recv was interrupted, discard the socket
762-
# and re-raise the exception.
761+
# recv was interrupted
763762
self.__pool.discard_socket(sock_info)
764763
raise
765764
if chunk == EMPTY:
@@ -816,12 +815,12 @@ def _send_message_with_response(self, message,
816815
# Restore the socket's original timeout and return it to
817816
# the pool
818817
sock_info.sock.settimeout(self.__net_timeout)
819-
self.__pool.return_socket(sock_info)
818+
self.__pool.maybe_return_socket(sock_info)
820819
except socket.error:
821820
# There was an exception and we've closed the socket
822821
pass
823822
else:
824-
self.__pool.return_socket(sock_info)
823+
self.__pool.maybe_return_socket(sock_info)
825824

826825
def start_request(self):
827826
"""Ensure the current thread or greenlet always uses the same socket

0 commit comments

Comments
 (0)