question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deactivate auto reconnect for consumer

See original GitHub issue

Here is the problem

Sample code: use the next iterator, and go through. I handle my own timeouts, retries, what I do, when I commit (one message at a time), what I log, etc.

from kafka import KafkaConsumer
consumer = KafkaConsumer('mytopic', boostrap_servers='myserver', consumer_timeout_ms=1000, enable_auto_commit=False)

while True:
  try:
    print "start iteration"
    data = next(consumer)
    # do some processing, and if it went well, commit
    consumer.commit()
  except StopIteration:
    print "cycle back"

For normal processing, when kafka is running fine, it will print start interation, cycle back every second if I don’t have any new messages in my kafka topic, except that if I stop kafka, it will block at the next(consumer) forever. And then if I restart kafka, it will reconnect and do as if nothing had gone wrong.

How can I stop the “magic” behavior? I’d like it to just throw an exception if it disconnects, and let me do the reconnect on my own terms.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
felipoucommented, Mar 24, 2018

Or an error event. If the client can’t connect to any broker at all, I’d like to know that. Perhaps there is a network issue on something, and I’d like to issue a warning so that someone can take action, or maybe just be aware that the client isn’t able to connect and possibly delayed.

0reactions
jeffwidmancommented, Feb 12, 2020

I’d like for this to exist as well, in containerized environments like kubernetes, if the cluster goes down and comes back up, the brokers will get different IPs, and the client will keep trying to refresh metadata from nonexistent brokers forever, with a timeout or a number of maximum retries, the client would die and kubernetes would fire it again.

Although unrelated to the original issue, that is a definite bug, we shouldn’t cache those IP’s forever. However, IIRC since this issue was last updated there have been a number of fixes to DNS resolution that have been merged.

I’m going to close this. If you can replicate this issue with the 2.x series, please open a new ticket and lets get it fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable auto reconnect network drive on boot - TechNet
Every time I boot Windows 7 now, I get a popup saying Windows 7 was unable to auto reconnect network drives . In...
Read more >
How to avoid automatic reconnect to data sources at startup?
My question is about the following scenario. I close Data Studio (4.1.1 / Linux) with some SQL Script files open that are connected...
Read more >
How do I disable auto connect from WiFi? - Quora
In Windows 10, there are two ways of doing this: 1. Click on the network icon, select the network and untick the “Connect...
Read more >
spring - Activemq consumer can not reconnect automatically
PooledConnectionFactory closes sessions/consumer connection after the consumer has processed messages.Hence the consumer count keeps ...
Read more >
How to enable/disable the Auto-Connect to a database feature ...
How to enable or disable the Auto-Connect to a specified database feature? How to stop Toad from auto-connecting to my schema?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found