{"record":{"id":"99396fcc728a13f2","repo":"openzipkin/zipkin","slug":"timeout-establishing-connection-to-rabbitmq-server","errorCode":null,"errorMessage":"Timeout establishing connection to RabbitMQ server: {e.getMessage()}","messagePattern":"Timeout establishing connection to RabbitMQ server: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"zipkin-collector/rabbitmq/src/main/java/zipkin2/collector/rabbitmq/RabbitMQCollector.java","lineNumber":181,"sourceCode":"\n    void close() throws IOException {\n      Connection maybeConnection = connection;\n      if (maybeConnection != null) maybeConnection.close();\n    }\n\n    Connection compute() {\n      Connection connection;\n      try {\n        connection =\n          (builder.addresses == null)\n            ? builder.connectionFactory.newConnection()\n            : builder.connectionFactory.newConnection(builder.addresses);\n        declareQueueIfMissing(connection);\n      } catch (IOException e) {\n        throw new UncheckedIOException(\n          \"Unable to establish connection to RabbitMQ server: \" + e.getMessage(), e);\n      } catch (TimeoutException e) {\n        throw new RuntimeException(\n          \"Timeout establishing connection to RabbitMQ server: \" + e.getMessage(), e);\n      }\n      Collector collector = builder.delegate.build();\n      CollectorMetrics metrics = builder.metrics;\n\n      for (int i = 0; i < builder.concurrency; i++) {\n        String consumerTag = \"zipkin-rabbitmq.\" + i;\n        try {\n          // this sets up a channel for each consumer thread.\n          // We don't track channels, as the connection will close its channels implicitly\n          Channel channel = connection.createChannel();\n          RabbitMQSpanConsumer consumer = new RabbitMQSpanConsumer(channel, collector, metrics);\n          channel.basicConsume(builder.queue, true, consumerTag, consumer);\n        } catch (IOException e) {\n          throw new IllegalStateException(\"Failed to start RabbitMQ consumer \" + consumerTag, e);\n        }\n      }\n      return connection;","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-collector/rabbitmq/src/main/java/zipkin2/collector/rabbitmq/RabbitMQCollector.java#L163-L199","documentation":"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.","triggerScenarios":"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().","commonSituations":"Kubernetes NetworkPolicy/firewall dropping port 5672 traffic, TLS-enabled broker contacted over plaintext (or vice versa), or heavily loaded broker during incident conditions.","solutions":["Check the wrapped TimeoutException and broker logs to see whether the connection attempt arrived at all","Verify network path and port (nc -zv rabbitmq 5672) and that nothing is dropping packets","Align TLS settings: factory.useSslProtocol() if the broker requires TLS","Tune factory.setConnectionTimeout() if the broker is legitimately slow, and add startup retry with backoff"],"exampleFix":"// before\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(\"rabbitmq\"); // firewall DROPs 5672 -> timeout\n\n// after\n// fix network/firewall to allow 5672, and make the failure fast + retriable:\nConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(\"rabbitmq\");\nfactory.setConnectionTimeout(10_000);","handlingStrategy":"retry","validationCode":"ConnectionFactory factory = new ConnectionFactory();\nfactory.setHost(host); factory.setPort(port);\nfactory.setConnectionTimeout(10_000); // fail fast instead of 60s stall\nif (useTls) factory.useSslProtocol();","typeGuard":null,"tryCatchPattern":"try {\n  collector.check();\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof TimeoutException) {\n    log.error(\"RabbitMQ handshake timed out — check firewall/TLS alignment\");\n  }\n  throw e;\n}","preventionTips":["Verify the network path allows 5672/5671 (DROP firewalls manifest as timeouts, not refusals)","Match TLS settings between client factory and broker","Set an explicit connection timeout so misconfigurations fail quickly"],"tags":["rabbitmq","zipkin","timeout","network","amqp"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}