Skip to content

Commit e9dcc24

Browse files
author
Dana Powers
committed
Fix BrokerConnection.connection_delay() -- return ms
1 parent 963a0e7 commit e9dcc24

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

kafka/conn.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,16 @@ def blacked_out(self):
594594
return False
595595

596596
def connection_delay(self):
597-
time_waited_ms = time.time() - (self.last_attempt or 0)
597+
"""
598+
Return the number of milliseconds to wait, based on the connection
599+
state, before attempting to send data. When disconnected, this respects
600+
the reconnect backoff time. When connecting, returns 0 to allow
601+
non-blocking connect to finish. When connected, returns a very large
602+
number to handle slow/stalled connections.
603+
"""
604+
time_waited = time.time() - (self.last_attempt or 0)
598605
if self.state is ConnectionStates.DISCONNECTED:
599-
return max(self._reconnect_backoff - time_waited_ms, 0)
606+
return max(self._reconnect_backoff - time_waited, 0) * 1000
600607
elif self.connecting():
601608
return 0
602609
else:

0 commit comments

Comments
 (0)