openzipkin/zipkin · critical · RuntimeException

Timeout establishing connection to RabbitMQ server: {e.getMe

Error message

Timeout establishing connection to RabbitMQ server: {e.getMessage()}

What it means

RabbitMQCollector's LazyInit.compute() wraps a TimeoutException from the AMQP connection handshake in a RuntimeException with this message. The ConnectionFactory has a connection timeout (default 60s); when the broker accepts TCP but never completes AMQP handshake (or the host is silently dropping packets), newConnection times out and this error propagates on first collector use.

Source

Thrown at zipkin-collector/rabbitmq/src/main/java/zipkin2/collector/rabbitmq/RabbitMQCollector.java:181

    void close() throws IOException {
      Connection maybeConnection = connection;
      if (maybeConnection != null) maybeConnection.close();
    }

    Connection compute() {
      Connection connection;
      try {
        connection =
          (builder.addresses == null)
            ? builder.connectionFactory.newConnection()
            : builder.connectionFactory.newConnection(builder.addresses);
        declareQueueIfMissing(connection);
      } catch (IOException e) {
        throw new UncheckedIOException(
          "Unable to establish connection to RabbitMQ server: " + e.getMessage(), e);
      } catch (TimeoutException e) {
        throw new RuntimeException(
          "Timeout establishing connection to RabbitMQ server: " + e.getMessage(), e);
      }
      Collector collector = builder.delegate.build();
      CollectorMetrics metrics = builder.metrics;

      for (int i = 0; i < builder.concurrency; i++) {
        String consumerTag = "zipkin-rabbitmq." + i;
        try {
          // this sets up a channel for each consumer thread.
          // We don't track channels, as the connection will close its channels implicitly
          Channel channel = connection.createChannel();
          RabbitMQSpanConsumer consumer = new RabbitMQSpanConsumer(channel, collector, metrics);
          channel.basicConsume(builder.queue, true, consumerTag, consumer);
        } catch (IOException e) {
          throw new IllegalStateException("Failed to start RabbitMQ consumer " + consumerTag, e);
        }
      }
      return connection;

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Check the wrapped TimeoutException and broker logs to see whether the connection attempt arrived at all
  2. Verify network path and port (nc -zv rabbitmq 5672) and that nothing is dropping packets
  3. Align TLS settings: factory.useSslProtocol() if the broker requires TLS
  4. Tune factory.setConnectionTimeout() if the broker is legitimately slow, and add startup retry with backoff

Example fix

// before
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("rabbitmq"); // firewall DROPs 5672 -> timeout

// after
// fix network/firewall to allow 5672, and make the failure fast + retriable:
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("rabbitmq");
factory.setConnectionTimeout(10_000);
Defensive patterns

Strategy: retry

Validate before calling

ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host); factory.setPort(port);
factory.setConnectionTimeout(10_000); // fail fast instead of 60s stall
if (useTls) factory.useSslProtocol();

Try / catch

try {
  collector.check();
} catch (RuntimeException e) {
  if (e.getCause() instanceof TimeoutException) {
    log.error("RabbitMQ handshake timed out — check firewall/TLS alignment");
  }
  throw e;
}

Prevention

When it happens

Trigger: Broker overloaded, network black-holing packets (firewall DROP instead of REJECT), wrong TLS settings causing handshake stall, or a misconfigured address that routes to a non-AMQP service. Thrown from newConnection() within compute().

Common situations: Kubernetes NetworkPolicy/firewall dropping port 5672 traffic, TLS-enabled broker contacted over plaintext (or vice versa), or heavily loaded broker during incident conditions.

Understand the failure class

Related errors


AI-assisted analysis of openzipkin/zipkin@878ce2a1fa (2026-08-14). Data as JSON: /api/errors/99396fcc728a13f2. Report an issue: GitHub.