diff --git a/src/main/java/org/tikv/common/TiSession.java b/src/main/java/org/tikv/common/TiSession.java index 449d8765645..dc45e438796 100644 --- a/src/main/java/org/tikv/common/TiSession.java +++ b/src/main/java/org/tikv/common/TiSession.java @@ -77,6 +77,10 @@ public class TiSession implements AutoCloseable { private static final int MAX_SPLIT_REGION_STACK_DEPTH = 6; public TiSession(TiConfiguration conf) { + // may throw org.tikv.common.MetricsServer - http server not up + // put it at the beginning of this function to avoid unclosed Thread + this.metricsServer = MetricsServer.getInstance(conf); + this.conf = conf; this.channelFactory = conf.isTlsEnable() @@ -92,7 +96,6 @@ public TiSession(TiConfiguration conf) { this.client = PDClient.createRaw(conf, channelFactory); this.enableGrpcForward = conf.getEnableGrpcForward(); - this.metricsServer = MetricsServer.getInstance(conf); if (this.enableGrpcForward) { logger.info("enable grpc forward for high available"); }