diff --git a/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java b/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java index 791db903..5f934a98 100755 --- a/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java +++ b/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/transport/config/TransportConfig.java @@ -42,6 +42,10 @@ public class TransportConfig { return SentinelConfig.getConfig(CONSOLE_SERVER); } + public static int getRuntimePort() { + return runtimePort; + } + /** * Get Server port of this HTTP server. * diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java index 66c4bb85..f073ccaf 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/command/SimpleHttpCommandCenter.java @@ -124,9 +124,7 @@ public class SimpleHttpCommandCenter implements CommandCenter { } } - if (success) { - tmpPort = port; - } else { + if (!success) { tmpPort = PORT_UNINITIALIZED; } TransportConfig.setRuntimePort(tmpPort); diff --git a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java index 4eff03c9..1fce5612 100755 --- a/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java +++ b/sentinel-transport/sentinel-transport-simple-http/src/main/java/com/alibaba/csp/sentinel/transport/heartbeat/SimpleHttpHeartbeatSender.java @@ -52,7 +52,7 @@ public class SimpleHttpHeartbeatSender implements HeartbeatSender { public SimpleHttpHeartbeatSender() { // Retrieve the list of default addresses. List newAddrs = getDefaultConsoleIps(); - RecordLog.info("Default console address list retrieved: " + newAddrs); + RecordLog.info("[SimpleHttpHeartbeatSender] Default console address list retrieved: " + newAddrs); this.addressList = newAddrs; // Set interval config. String interval = System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS, String.valueOf(DEFAULT_INTERVAL)); @@ -61,6 +61,10 @@ public class SimpleHttpHeartbeatSender implements HeartbeatSender { @Override public boolean sendHeartbeat() throws Exception { + if (TransportConfig.getRuntimePort() <= 0) { + RecordLog.info("[SimpleHttpHeartbeatSender] Runtime port not initialized, won't send heartbeat"); + return false; + } InetSocketAddress addr = getAvailableAddress(); if (addr == null) { return false;