@Override protected void startUp() throws Exception { int tries = 0; do { KafkaConfig kafkaConfig = createKafkaConfig(properties); KafkaServer kafkaServer = createKafkaServer(kafkaConfig); try { kafkaServer.startup(); server = kafkaServer; } catch (Exception e) { kafkaServer.shutdown(); kafkaServer.awaitShutdown(); Throwable rootCause = Throwables.getRootCause(e); if (rootCause instanceof ZkTimeoutException) { // Potentially caused by race condition bug described in TWILL-139. LOG.warn("Timeout when connecting to ZooKeeper from KafkaServer. Attempt number {}.", tries, rootCause); } else if (rootCause instanceof BindException) { LOG.warn("Kafka failed to bind to port {}. Attempt number {}.", kafkaConfig.port(), tries, rootCause); } else { throw e; } // Do a random sleep of < 200ms TimeUnit.MILLISECONDS.sleep(new Random().nextInt(200) + 1L); } } while (server == null && ++tries < startTimeoutRetries); if (server == null) { throw new IllegalStateException("Failed to start Kafka server after " + tries + " attempts."); } }
@Override protected void startUp() throws Exception { int tries = 0; do { KafkaConfig kafkaConfig = createKafkaConfig(properties); KafkaServer kafkaServer = createKafkaServer(kafkaConfig); try { kafkaServer.startup(); server = kafkaServer; } catch (Exception e) { kafkaServer.shutdown(); kafkaServer.awaitShutdown(); Throwable rootCause = Throwables.getRootCause(e); if (rootCause instanceof ZkTimeoutException) { // Potentially caused by race condition bug described in TWILL-139. LOG.warn("Timeout when connecting to ZooKeeper from KafkaServer. Attempt number {}.", tries, rootCause); } else if (rootCause instanceof BindException) { LOG.warn("Kafka failed to bind to port {}. Attempt number {}.", kafkaConfig.port(), tries, rootCause); } else { throw e; } // Do a random sleep of < 200ms TimeUnit.MILLISECONDS.sleep(new Random().nextInt(200) + 1L); } } while (server == null && ++tries < startTimeoutRetries); if (server == null) { throw new IllegalStateException("Failed to start Kafka server after " + tries + " attempts."); } }