Skip to content

Commit cb31845

Browse files
author
Dana Powers
committed
Shutdown socket before closing in kafka.conn
1 parent 7b9322f commit cb31845

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kafka/conn.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ def close(self):
155155
"""
156156
log.debug("Closing socket connection for %s:%d" % (self.host, self.port))
157157
if self._sock:
158+
# Call shutdown to be a good TCP client
159+
# But expect an error if the socket has already been
160+
# closed by the server
161+
try:
162+
self._sock.shutdown(socket.SHUT_RDWR)
163+
except socket.error:
164+
pass
165+
166+
# Closing the socket should always succeed
158167
self._sock.close()
159168
self._sock = None
160169
else:

0 commit comments

Comments
 (0)