kafka.common.KafkaTimeoutError: ('Failed to update metadata after %s secs.', 60.0)
kafka version: 0.8.2.0-1.kafka1.3.2.p0.15 (cloudera released)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/archimonde/lib/python2.6/site-packages/kafka/producer/kafka.py", line 357, in send
self._wait_on_metadata(topic, self.config['max_block_ms'] / 1000.0)
File "/opt/archimonde/lib/python2.6/site-packages/kafka/producer/kafka.py", line 465, in _wait_on_metadata
"Failed to update metadata after %s secs.", max_wait)
kafka.common.KafkaTimeoutError: ('Failed to update metadata after %s secs.', 60.0)
But it's ok on 2.0.0-1.kafka2.0.0.p0.12.
resolved. must set all brokers for bootstrap_servers.
@archiechen I am getting the same error too, what did you do?
so what is the fix here?
Also wondering fix. I see this error when running kafka via Docker but not when installing from binary.
EDIT: So wondering what the root cause may be to help me pinpoint issues between environments.
Anyone get an answer to this?
docker default binds to ipv6 only. but usually you may miss configuring listeners of it. related to https://github.com/moby/moby/issues/2174.
I am re-opening, I also saw the same issue in production with kafka-python 1.3.5 and kafka broker 0.10.0.1. The producer was a VM, the broker was baremetal--no docker here.
The error showed up after rolling the kafka cluster, and the KafkaProducer instance never recovered, just continually threw this error once a minute. The brokers were rolled by stopping/restarting the broker processes--the underlying machines did not change and DNS was not affected.
I watched the tcp stream and the producer never tried to even talk to Kafka, so it wasn't timing out cluster side.
When I restarted the service, it immediately started working.
I too saw this exact issue with kafka-python 1.3.5 and kafka broker 1.0.0. I tried restarting one of the brokers, and now I continually get the following message:
kafka.errors.KafkaTimeoutError: KafkaTimeoutError: Failed to update metadata after 60.0 secs.
My producer is running inside a docker container, but both kafka brokers are running in linux via supervisor. Both of my brokers are included via bootstrap_servers.
Another cause for this issue is using a bytes object as the topic name, instead of a string. In python 3, you could have a string come in as a bytes object (a = b'test_string'). If this happens, you can just convert the topic name to a utf-8 string, and it might start working. It worked for me.
if type(kafka_topic) == bytes:
kafka_topic = kafka_topic.decode('utf-8')
kafka_producer = KafkaProducer(bootstrap_servers=kafka_brokers)
kafka_producer.send(kafka_topic, payload)
kafka_producer.flush()
Steps to reproduce the issue:
- Clone Kafka Docker repo
git clone https://github.com/wurstmeister/kafka-docker - Clone kafka-python repo
git clone https://github.com/dpkp/kafka-python - Start Kafka
( cd kafka-docker; docker-compose up -d ) - Find out Kafka broker port
docker ps - Set correct broker port in example.py
cd kafka-python; vi example.py(line 17 and 35) - Execute example
python example.py
here's the logs right before the timeout:
DEBUG 2018-02-24 05:38:58,420 kafka 46849 Requesting metadata update for topic ('example',)
DEBUG 2018-02-24 05:38:58,520 client_async 46849 Sending metadata request MetadataRequest_v1(topics=[('example',)]) to node 1011
DEBUG 2018-02-24 05:38:58,520 parser 46849 Sending request MetadataRequest_v1(topics=[('example',)])
DEBUG 2018-02-24 05:38:58,520 conn 46849 <BrokerConnection node_id=1011 host=localhost/::1 port=9092> Request 562: MetadataRequest_v1(topics=[('example',)])
DEBUG 2018-02-24 05:38:58,523 parser 46849 Received correlation id: 562
DEBUG 2018-02-24 05:38:58,523 parser 46849 Processing response MetadataResponse_v1
DEBUG 2018-02-24 05:38:58,523 conn 46849 <BrokerConnection node_id=1011 host=localhost/::1 port=9092> Response 562 (3.287076950073242 ms): MetadataResponse_v1(brokers=[(node_id=1011, host='localhost', port=9092, rack=None)], controller_id=1011, topics=[(error_code=17, topic="('example',)", is_internal=False, partitions=[])])
DEBUG 2018-02-24 05:38:58,523 kafka 46849 _wait_on_metadata woke after 59.96455192565918 secs.
DEBUG 2018-02-24 05:38:58,524 kafka 46849 Requesting metadata update for topic ('example',)
Traceback (most recent call last):
File "/Users/dustin/.virtualenvs/oda-data-pipe/bin/oda", line 11, in <module>
load_entry_point('oda-data-pipe', 'console_scripts', 'oda')()
File "/Users/dustin/Work/cu/oda-data-pipe/oda_data_pipe/main.py", line 150, in main
args.func(args)
File "/Users/dustin/Work/cu/oda-data-pipe/oda_data_pipe/main.py", line 28, in produce
job_module.extract()
File "/Users/dustin/Work/cu/oda-data-pipe/oda_data_pipe/oda_producer.py", line 53, in wrapper
kafka_producer.send(topic_name, item)
File "/Users/dustin/.virtualenvs/oda-data-pipe/lib/python3.6/site-packages/kafka/producer/kafka.py", line 546, in send
self._wait_on_metadata(topic, self.config['max_block_ms'] / 1000.0)
File "/Users/dustin/.virtualenvs/oda-data-pipe/lib/python3.6/site-packages/kafka/producer/kafka.py", line 664, in _wait_on_metadata
"Failed to update metadata after %.1f secs." % max_wait)
kafka.errors.KafkaTimeoutError: KafkaTimeoutError: Failed to update metadata after 60.0 secs.
INFO 2018-02-24 05:38:58,561 kafka 46849 Closing the Kafka producer with 0 secs timeout.
INFO 2018-02-24 05:38:58,561 kafka 46849 Proceeding to force close the producer since pending requests could not be completed within timeout 0.
DEBUG 2018-02-24 05:38:58,562 sender 46849 Beginning shutdown of Kafka producer I/O thread, sending remaining records.
INFO 2018-02-24 05:38:58,562 conn 46849 <BrokerConnection node_id=1011 host=localhost/::1 port=9092>: Closing connection.
DEBUG 2018-02-24 05:38:58,563 conn 46849 <BrokerConnection node_id=1011 host=localhost/::1 port=9092>: reconnect backoff 0.04849831291093153 after 1 failures
DEBUG 2018-02-24 05:38:58,563 sender 46849 Shutdown of Kafka producer I/O thread has completed.
DEBUG 2018-02-24 05:38:58,563 kafka 46849 The Kafka producer has closed.
INFO 2018-02-24 05:38:58,572 kafka 46849 Kafka producer closed
I've also noticed that using kafka-python in the interpreter works just fine, with the exact same bootstrap_servers and everything else. The bug only surfaces when executed as part of a Python program.
If this happens before any message is able to be sent then it typically indicates a low-level connection error. Take a look at the kafka.conn.BrokerConnection debug logs. I've made several changes to the network connection code on master to handle various edge cases that you may be hitting. If you are able to test with master, can you check whether this issue is fixed now?
I am having the same issue with 1.4.2 and 1.4.3-dev0. Do not understand where i can find the debug logs you are talking about. Would they be somewhere in the docker volume?
Traceback (most recent call last):
File "producer.py", line 41, in <module>
producer.send('answer_topic', value=message)
File "/usr/local/lib/python3.5/dist-packages/kafka/producer/kafka.py", line 543, in send
self._wait_on_metadata(topic, self.config['max_block_ms'] / 1000.0)
File "/usr/local/lib/python3.5/dist-packages/kafka/producer/kafka.py", line 664, in _wait_on_metadata
"Failed to update metadata after %.1f secs." % max_wait)
kafka.errors.KafkaTimeoutError: KafkaTimeoutError: Failed to update metadata after 60.0 secs.
to enable python logging at its most simple form:
import logging
logging.basicConfig(level=logging.DEBUG)
I am having the same issue while using minikube and https://github.com/Yolean/kubernetes-kafka (Kubernetes version 1.9.0, Kafka 1.0)
Whats the fix for this issue guys?
If running the kafka brokers inside a container, make sure that it advertises the correct hostnames that are accessible by the clients. If not specified it will use the canonical hostname of the container and that may be an internal one that cannot be used outside of the container.
You can set the advertised hosts with advertised.listeners in the server properties, or if you just want to test with an unmodified kafka docker image, you can override the default setting with:
bin/kafka-server-start.sh config/server.properties --override advertised.listeners=PLAINTEXT://<accessible-hostname>:9092
I had same problem, To solve the problem I increased request_timeout_ms (I used 10ms before)
Had the same issue. Was producing against a kafka cluster which was not available, changing the cluster address to an available one fixed the problem for me