summaryrefslogtreecommitdiff
path: root/kafka/conn.py
diff options
context:
space:
mode:
Diffstat (limited to 'kafka/conn.py')
-rw-r--r--kafka/conn.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/kafka/conn.py b/kafka/conn.py
index 2e37ecf..33c799c 100644
--- a/kafka/conn.py
+++ b/kafka/conn.py
@@ -155,6 +155,15 @@ class KafkaConnection(local):
"""
log.debug("Closing socket connection for %s:%d" % (self.host, self.port))
if self._sock:
+ # Call shutdown to be a good TCP client
+ # But expect an error if the socket has already been
+ # closed by the server
+ try:
+ self._sock.shutdown(socket.SHUT_RDWR)
+ except socket.error:
+ pass
+
+ # Closing the socket should always succeed
self._sock.close()
self._sock = None
else: