kafka-python
kafka-python copied to clipboard
Setting connections_max_idle_ms to zero causes error
If you set connections_max_idle_ms to 0, the following code is used to configure the client:
class IdleConnectionManager(object):
def __init__(self, connections_max_idle_ms):
if connections_max_idle_ms > 0:
self.connections_max_idle = connections_max_idle_ms / 1000
else:
self.connections_max_idle = float('inf')
from https://github.com/dpkp/kafka-python/blob/master/kafka/client_async.py. This code looks like it tries to avoid a division by zero (0 / 1000
), except that that is not a division by zero at all; it's just zero. As such, this gets mapped to infinity and then further down:
def next_check_ms(self):
now = time.time()
if not self.lru_connections:
return float('inf')
elif self.next_idle_close_check_time <= now:
return 0
else:
return int((self.next_idle_close_check_time - now) * 1000)
gets called, which evaluates as return int(float('inf'))
and blows up OverflowError: cannot convert float infinity to integer
.
I think zero should work here to disable the idle time entirely and perhaps -1 should be the special infinite value to never timeout under idle conditions.