From 36c1afed77cf84063e693e5678d5445b2a6a0e3a Mon Sep 17 00:00:00 2001 From: marsishandsome Date: Thu, 28 Oct 2021 16:09:15 +0800 Subject: [PATCH] fix unclosed Thread when create TiSession error Signed-off-by: marsishandsome --- src/main/java/org/tikv/common/TiSession.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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"); }