kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

kafka.common.KafkaTimeoutError: ('Failed to update metadata after %s secs.', 60.0)

Open archiechen opened this issue 10 years ago • 52 comments

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.

archiechen avatar Mar 18 '16 00:03 archiechen

resolved. must set all brokers for bootstrap_servers.

archiechen avatar Mar 18 '16 01:03 archiechen

@archiechen I am getting the same error too, what did you do?

khangnguyen avatar Oct 27 '16 09:10 khangnguyen

so what is the fix here?

jasonrhaas avatar Dec 14 '16 09:12 jasonrhaas

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.

nicholasserra avatar Jan 25 '17 20:01 nicholasserra

Anyone get an answer to this?

lukewendling avatar Jul 12 '17 14:07 lukewendling

docker default binds to ipv6 only. but usually you may miss configuring listeners of it. related to https://github.com/moby/moby/issues/2174.

softwarevamp avatar Sep 01 '17 11:09 softwarevamp

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.

jeffwidman avatar Dec 02 '17 02:12 jeffwidman

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.

geoff-va avatar Jan 10 '18 19:01 geoff-va

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()

griff122 avatar Feb 13 '18 18:02 griff122

Steps to reproduce the issue:

  1. Clone Kafka Docker repo git clone https://github.com/wurstmeister/kafka-docker
  2. Clone kafka-python repo git clone https://github.com/dpkp/kafka-python
  3. Start Kafka ( cd kafka-docker; docker-compose up -d )
  4. Find out Kafka broker port docker ps
  5. Set correct broker port in example.py cd kafka-python; vi example.py (line 17 and 35)
  6. Execute example python example.py

brennerm avatar Feb 20 '18 10:02 brennerm

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

dustinfarris avatar Feb 23 '18 21:02 dustinfarris

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.

dustinfarris avatar Feb 23 '18 21:02 dustinfarris

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?

dpkp avatar Mar 09 '18 22:03 dpkp

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.

benkibejs avatar Mar 19 '18 14:03 benkibejs

to enable python logging at its most simple form:

import logging
logging.basicConfig(level=logging.DEBUG)

dpkp avatar Mar 23 '18 01:03 dpkp

I am having the same issue while using minikube and https://github.com/Yolean/kubernetes-kafka (Kubernetes version 1.9.0, Kafka 1.0)

tkaymak avatar Apr 16 '18 08:04 tkaymak

Whats the fix for this issue guys?

GagandeepS avatar Jun 11 '18 17:06 GagandeepS

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

madss avatar Jul 05 '18 13:07 madss

I had same problem, To solve the problem I increased request_timeout_ms (I used 10ms before)

mikekeda avatar Sep 12 '18 15:09 mikekeda

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

egodigitus avatar Sep 14 '18 06:09 egodigitus