Skip to content
Latchkey

Kafka "TimeoutException: Topic not present in metadata" in CI

The producer blocked waiting for metadata about a topic and the wait expired. The broker either does not know that topic (it was never created and auto-create is off) or was still starting when the send ran.

What this error means

A send fails with "org.apache.kafka.common.errors.TimeoutException: Topic orders not present in metadata after 60000 ms." after a long pause.

Terminal
org.apache.kafka.common.errors.TimeoutException:
Topic orders not present in metadata after 60000 ms.

Common causes

The topic does not exist and auto-create is off

With auto-creation disabled, metadata for an uncreated topic never appears, so the producer waits out the full timeout.

The broker was not ready when the producer started

A producer that connects during broker startup cannot fetch metadata until the broker finishes booting.

How to fix it

Create the topic before producing

Create it as a setup step so metadata is available immediately.

Terminal
kafka-topics.sh --bootstrap-server localhost:9092 \
  --create --if-not-exists --topic orders --partitions 1 --replication-factor 1

Wait for the broker before the first send

Poll an admin call until the broker answers, then run the producer.

Terminal
until kafka-topics.sh --bootstrap-server localhost:9092 --list >/dev/null 2>&1; do
  echo "waiting for kafka"; sleep 3
done

How to prevent it

  • Create topics explicitly in a setup step before producing.
  • Gate the producer on broker readiness.
  • Keep the metadata timeout generous for a slow first start.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →