Skip to content

Commit 946d927

Browse files
committed
Merge pull request #462 from basho/fixes/lrb/socket-exception-gh-461
READY: Catch environment exceptions when socket.shutdown() is called
2 parents eb91c87 + 7c39f3f commit 946d927

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

riak/transports/tcp/connection.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import errno
1+
import logging
22
import socket
33
import struct
44

@@ -19,12 +19,6 @@
1919

2020

2121
class TcpConnection(object):
22-
# These are set in the TcpTransport initializer
23-
_address = None
24-
_timeout = None
25-
_socket_keepalive = None
26-
_socket_tcp_options = None
27-
2822
"""
2923
Connection-related methods for TcpTransport.
3024
"""
@@ -228,10 +222,11 @@ def close(self):
228222
# shutdown() method due to the SSL lib
229223
try:
230224
self._socket.shutdown(socket.SHUT_RDWR)
231-
except IOError as e:
232-
# NB: sometimes this is the exception if the initial
233-
# connection didn't succeed correctly
234-
if e.errno != errno.EBADF:
235-
raise
225+
except EnvironmentError:
226+
# NB: sometimes these exceptions are raised if the initial
227+
# connection didn't succeed correctly, or if shutdown() is
228+
# called after the connection dies
229+
logging.debug('Exception occurred while shutting '
230+
'down socket.', exc_info=True)
236231
self._socket.close()
237232
del self._socket

0 commit comments

Comments
 (0)