From 489e5c22ec7cfafb13a63ba54816fc0c8e85b498 Mon Sep 17 00:00:00 2001 From: Liangliang Gu Date: Thu, 28 Oct 2021 16:28:27 +0800 Subject: [PATCH] fix unclosed Thread when create TiSession error (#300) 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 449d876564..dc45e43879 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 class TiSession implements AutoCloseable { 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"); }