diff --git a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/server/EmbeddedZkServer.scala b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/server/EmbeddedZkServer.scala index ddda84892..a75bad0ec 100644 --- a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/server/EmbeddedZkServer.scala +++ b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/server/EmbeddedZkServer.scala @@ -58,6 +58,12 @@ class EmbeddedZkServer private(name: String) extends AbstractService(name) with override def stop(): Unit = { if (server != null) { + // Just a tradeoff, otherwise we may get NPE if we call stop() immediately. + // (e.g. the unit test EmbeddedZkServerSuite) + // TestingZooKeeperMain has a bug that the CountDownLatch released before cnxnFactory inited. + // More details could see TestingZooKeeperMain.runFromConfig. + while (getStartTime > 0 && System.currentTimeMillis() - getStartTime < 5000) { + } server.close() server = null }