summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Powers <dana.powers@gmail.com>2018-03-09 11:26:34 -0500
committerGitHub <noreply@github.com>2018-03-09 11:26:34 -0500
commit4cbeb2e591447ba25271c4924393e602ba49b324 (patch)
treecbbeab3ec4de834f383e4b2aa6c646954e0a4b26
parent1974dc19c5eac1527b99bae8e348557abe5cdcd2 (diff)
downloadkafka-python-4cbeb2e591447ba25271c4924393e602ba49b324.tar.gz
Short-circuit BrokerConnection.close() if already disconnected (#1424)
-rw-r--r--kafka/conn.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/kafka/conn.py b/kafka/conn.py
index c2ac28e..b0d6029 100644
--- a/kafka/conn.py
+++ b/kafka/conn.py
@@ -665,10 +665,13 @@ class BrokerConnection(object):
will be failed with this exception.
Default: kafka.errors.ConnectionError.
"""
+ if self.state is ConnectionStates.DISCONNECTED:
+ if error is not None:
+ log.warning('%s: Duplicate close() with error: %s', self, error)
+ return
log.info('%s: Closing connection. %s', self, error or '')
- if self.state is not ConnectionStates.DISCONNECTED:
- self.state = ConnectionStates.DISCONNECTING
- self.config['state_change_callback'](self)
+ self.state = ConnectionStates.DISCONNECTING
+ self.config['state_change_callback'](self)
self._update_reconnect_backoff()
self._close_socket()
self.state = ConnectionStates.DISCONNECTED