summaryrefslogtreecommitdiff
path: root/kafka
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2018-03-07 18:06:27 -0800
committerDana Powers <dana.powers@rd.io>2018-03-07 18:06:27 -0800
commit74157f4caf5f158781df41128738256a2500e6d0 (patch)
tree8d07b1bb19558ec3f9fb04cea369f74ec022ca5c /kafka
parentd40a440a79626eb678cc12b5893d8be769b2c04d (diff)
downloadkafka-python-conn_delay_ms.tar.gz
Fix BrokerConnection.connection_delay() -- return msconn_delay_ms
Diffstat (limited to 'kafka')
-rw-r--r--kafka/conn.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/kafka/conn.py b/kafka/conn.py
index 0c8ae9a..d778c31 100644
--- a/kafka/conn.py
+++ b/kafka/conn.py
@@ -594,9 +594,16 @@ class BrokerConnection(object):
return False
def connection_delay(self):
- time_waited_ms = time.time() - (self.last_attempt or 0)
+ """
+ Return the number of milliseconds to wait, based on the connection
+ state, before attempting to send data. When disconnected, this respects
+ the reconnect backoff time. When connecting, returns 0 to allow
+ non-blocking connect to finish. When connected, returns a very large
+ number to handle slow/stalled connections.
+ """
+ time_waited = time.time() - (self.last_attempt or 0)
if self.state is ConnectionStates.DISCONNECTED:
- return max(self._reconnect_backoff - time_waited_ms, 0)
+ return max(self._reconnect_backoff - time_waited, 0) * 1000
elif self.connecting():
return 0
else: