Skip to content

Commit 4cbeb2e

Browse files
authored
Short-circuit BrokerConnection.close() if already disconnected (#1424)
1 parent 1974dc1 commit 4cbeb2e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kafka/conn.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,13 @@ def close(self, error=None):
665665
will be failed with this exception.
666666
Default: kafka.errors.ConnectionError.
667667
"""
668+
if self.state is ConnectionStates.DISCONNECTED:
669+
if error is not None:
670+
log.warning('%s: Duplicate close() with error: %s', self, error)
671+
return
668672
log.info('%s: Closing connection. %s', self, error or '')
669-
if self.state is not ConnectionStates.DISCONNECTED:
670-
self.state = ConnectionStates.DISCONNECTING
671-
self.config['state_change_callback'](self)
673+
self.state = ConnectionStates.DISCONNECTING
674+
self.config['state_change_callback'](self)
672675
self._update_reconnect_backoff()
673676
self._close_socket()
674677
self.state = ConnectionStates.DISCONNECTED

0 commit comments

Comments
 (0)