Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout must not be negative #40

Open
gfelixc opened this issue Mar 17, 2020 · 4 comments
Open

Timeout must not be negative #40

gfelixc opened this issue Mar 17, 2020 · 4 comments
Labels

Comments

@gfelixc
Copy link

gfelixc commented Mar 17, 2020

Container fails sometimes with following error

Traceback (most recent call last):
  File "/usr/local/bin/prometheus-kafka-consumer-group-exporter", line 11, in <module>
    load_entry_point('prometheus-kafka-consumer-group-exporter', 'console_scripts', 'prometheus-kafka-consumer-group-exporter')()
  File "/usr/src/app/prometheus_kafka_consumer_group_exporter/__init__.py", line 165, in main
    for message in consumer:
  File "/usr/local/lib/python3.8/site-packages/kafka/consumer/group.py", line 1181, in __next__
    return self.next_v2()
  File "/usr/local/lib/python3.8/site-packages/kafka/consumer/group.py", line 1189, in next_v2
    return next(self._iterator)
  File "/usr/local/lib/python3.8/site-packages/kafka/consumer/group.py", line 1106, in _message_generator_v2
    record_map = self.poll(timeout_ms=timeout_ms, update_offsets=False)
  File "/usr/local/lib/python3.8/site-packages/kafka/consumer/group.py", line 635, in poll
    assert timeout_ms >= 0, 'Timeout must not be negative'
AssertionError: Timeout must not be negative

Any ideas?

@braedon
Copy link
Owner

braedon commented Mar 20, 2020

Hi @gfelixc, that's not something I've seen, but it looks like it might be a bug in the kafka-python library.

In KafkaConsumer, next_v2() sets _consumer_timeout to some time in the future (based on consumer_timeout_ms), and then calls next() on _message_generator_v2() while _consumer_timeout hasn't been reached. _message_generator_v2() then subtracts the current time (time.time()) from _consumer_timeout to get the timeout_ms to pass to poll().

If too much time elapses between checking if _consumer_timeout has been reached and calculating the timeout_ms, it could end up being negative. It seems like _message_generator_v2() should check for this, and use 0 if it calculates a negativetimeout_ms.

Assuming my quick analysis is correct, would you be able to raise an issue (or PR) with kafka-python to get this fixed?

@braedon
Copy link
Owner

braedon commented Mar 20, 2020

(Just to check - you haven't changed consumer_timeout_ms from the default 500ms, have you?)

@gfelixc
Copy link
Author

gfelixc commented Mar 20, 2020

Image has been deployed as is, no config changes. I'll raise to kafka-python as you suggest, and I'll let you know once fixed. Thanks a lot. Do you mind keep this ticket opened until kafka-python with fix would be updated?

@braedon
Copy link
Owner

braedon commented Mar 20, 2020

No worries, I'll keep this open. If you could link to the kafka-python issue once created it'd be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants