From beefb50f19a371c739c583cc0ff492683e7b4aba Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Mon, 15 May 2023 15:58:25 +0800 Subject: [PATCH] fix:fix random port read bug. (#1000) --- CHANGELOG.md | 1 + README-zh.md | 2 +- README.md | 2 +- .../cloud/polaris/context/PolarisSDKContextManager.java | 2 +- .../polaris/context/config/PolarisContextProperties.java | 8 +++----- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e51d0ceb..2448ce9ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,3 +7,4 @@ - [Feature: add AssemblyFlow to support tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/992) - [feat:refactor SDKContext as static.](https://github.com/Tencent/spring-cloud-tencent/pull/995) - [Refactoring: Refactor Circuitbreaker ut.](https://github.com/Tencent/spring-cloud-tencent/pull/996) +- [fix:fix random port read bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1000) diff --git a/README-zh.md b/README-zh.md index 35b05b550..905111ef8 100644 --- a/README-zh.md +++ b/README-zh.md @@ -78,7 +78,7 @@ Spring Cloud Tencent 所有组件都已上传到 Maven 中央仓库,只需要 com.tencent.cloud spring-cloud-tencent-dependencies - 1.11.2-2022.0.1 + 1.11.4-2022.0.1 pom import diff --git a/README.md b/README.md index 5b38c0623..a9f78a87a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ For example: com.tencent.cloud spring-cloud-tencent-dependencies - 1.11.2-2022.0.1 + 1.11.4-2022.0.1 pom import diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisSDKContextManager.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisSDKContextManager.java index 7ce3feabf..2f17db828 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisSDKContextManager.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisSDKContextManager.java @@ -127,7 +127,7 @@ public class PolarisSDKContextManager { // init SDKContext sdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList, () -> environment.getProperty("spring.cloud.client.ip-address"), - () -> environment.getProperty("server.port", Integer.class, 0))); + () -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0))); sdkContext.init(); // init ProviderAPI diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextProperties.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextProperties.java index 57cf2190d..7bde159b3 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextProperties.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextProperties.java @@ -83,10 +83,8 @@ public class PolarisContextProperties { defaultHost = ipAddressSupplier.get(); this.localIpAddress = defaultHost; } - Integer defaultPort = this.localPort; if (this.localPort == null || this.localPort <= 0) { - defaultPort = portSupplier.get(); - this.localPort = defaultPort; + this.localPort = portSupplier.get(); } configuration.getGlobal().getAPI().setBindIP(defaultHost); @@ -157,10 +155,10 @@ public class PolarisContextProperties { return "PolarisContextProperties{" + "address='" + address + '\'' + ", localIpAddress='" + localIpAddress + '\'' + - ", localPort=" + localPort + + ((this.localPort == null || this.localPort <= 0) ? "" : ", localPort=" + localPort) + ", enabled=" + enabled + ", namespace='" + namespace + '\'' + - ", service='" + service + '\'' + + ((StringUtils.isBlank(this.service)) ? "" : ", service='" + service + '\'') + '}'; } }