From 232d12b7060c4d909ad0e1e19954e9134fa8a02a Mon Sep 17 00:00:00 2001 From: shuiqingliu Date: Thu, 25 May 2023 17:18:52 +0800 Subject: [PATCH 1/4] feat: the polaris config relation non-daemon thread should stop when application fails to start. --- CHANGELOG.md | 1 + .../PolarisConfigAutoConfiguration.java | 7 +++ ...arisConfigNonDaemonThreadStopListener.java | 50 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 445aff571..cbf2b7c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,3 +27,4 @@ - [refactor:optimize discovery properties initialization.](https://github.com/Tencent/spring-cloud-tencent/pull/1079) - [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1085) - [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1094). +- [fix:the polaris config relation non-daemon thread should stop when application fails to start.](https://github.com/Tencent/spring-cloud-tencent/pull/1102) diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java index be91d2287..8b9bc3845 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java @@ -28,10 +28,12 @@ import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; import com.tencent.cloud.polaris.config.listener.PolarisConfigChangeEventListener; +import com.tencent.cloud.polaris.config.listener.PolarisConfigNonDaemonThreadStopListener; import com.tencent.cloud.polaris.config.listener.PolarisConfigRefreshOptimizationListener; import com.tencent.cloud.polaris.config.spring.annotation.SpringValueProcessor; import com.tencent.cloud.polaris.config.spring.property.PlaceholderHelper; import com.tencent.cloud.polaris.config.spring.property.SpringValueRegistry; +import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -62,6 +64,11 @@ public PolarisConfigChangeEventListener polarisConfigChangeEventListener() { return new PolarisConfigChangeEventListener(); } + @Bean + public PolarisConfigNonDaemonThreadStopListener polarisLongPullingStopListener(PolarisSDKContextManager polarisSDKContextManager) { + return new PolarisConfigNonDaemonThreadStopListener(polarisSDKContextManager); + } + @Bean @Primary @ConditionalOnReflectRefreshType diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java new file mode 100644 index 000000000..58e3f66b6 --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + */ + +package com.tencent.cloud.polaris.config.listener; + +import com.tencent.cloud.polaris.context.PolarisSDKContextManager; + +import org.springframework.boot.context.event.ApplicationFailedEvent; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.lang.NonNull; + +/* + * Polaris config non-daemon thread stop listener + * + * @author shuiqingliu + * @since 2023/8/29 + **/ +public class PolarisConfigNonDaemonThreadStopListener implements ApplicationListener { + + private final PolarisSDKContextManager polarisSDKContextManager; + + public PolarisConfigNonDaemonThreadStopListener(PolarisSDKContextManager polarisSDKContextManager) { + this.polarisSDKContextManager = polarisSDKContextManager; + } + + @Override + public void onApplicationEvent(@NonNull ApplicationEvent event) { + if (event instanceof ApplicationFailedEvent) { + //implicit invoke 'destroy' when the spring application fails to start, in order to stop non-daemon threads. + polarisSDKContextManager.getSDKContext().destroy(); + } + } + +} From c27c9d03859b796465d3aace629287d8e24bbfa2 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Tue, 12 Sep 2023 10:37:21 +0800 Subject: [PATCH 2/4] begin 1.13.0. --- CHANGELOG.md | 27 -------------------- changes/changes-1.12.0.md | 30 +++++++++++++++++++++++ pom.xml | 2 +- spring-cloud-tencent-dependencies/pom.xml | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 changes/changes-1.12.0.md diff --git a/CHANGELOG.md b/CHANGELOG.md index afe21b73a..06c1f8175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,3 @@ # Change Log --- -- [feature: support reactive discovery client health indicator.](https://github.com/Tencent/spring-cloud-tencent/pull/988) -- [feature: Enhance default configuration to support `application*.yaml` and `bootstrap*.yaml`.](https://github.com/Tencent/spring-cloud-tencent/pull/988) -- [feat:Remove error log from `DecodeTransferMetadataReactiveFilter`.](https://github.com/Tencent/spring-cloud-tencent/pull/991) -- [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) -- [docs:add release GitHub Action.](https://github.com/Tencent/spring-cloud-tencent/pull/1007) -- [docs:update Polaris test environment ip.](https://github.com/Tencent/spring-cloud-tencent/pull/1012) -- [fix:fix custom fallback exception.](https://github.com/Tencent/spring-cloud-tencent/pull/1022) -- [feat: sct-all package is now available as a shaded uber-jar.](https://github.com/Tencent/spring-cloud-tencent/pull/1025) -- [fix:use path parameter in `@FeignClient` for circuit-breaker.](https://github.com/Tencent/spring-cloud-tencent/pull/1028) -- [build(deps): bump guava in /spring-cloud-tencent-dependencies](https://github.com/Tencent/spring-cloud-tencent/pull/1037) -- [fix:fix reporting bug when port is -1.](https://github.com/Tencent/spring-cloud-tencent/pull/1040) -- [fix:update guava version.](https://github.com/Tencent/spring-cloud-tencent/pull/1043) -- [fix:fix circuit breaker bean load order bug when using Nacos discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1050) -- [refactor:refactor Polaris registration.](https://github.com/Tencent/spring-cloud-tencent/pull/1057) -- [feat:added automatic optimization for dynamic config refresh type.](https://github.com/Tencent/spring-cloud-tencent/pull/1058) -- [fix:fix SCG report wrong service bug when using IP routing.](https://github.com/Tencent/spring-cloud-tencent/pull/1065) -- [fix:fix gray release examples bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1068) -- [fix:fix router label feign interceptor order.](https://github.com/Tencent/spring-cloud-tencent/pull/1071) -- [feat:added polaris weighted round robin load balancer.](https://github.com/Tencent/spring-cloud-tencent/pull/1073) -- [fix:add deregister judgment.](https://github.com/Tencent/spring-cloud-tencent/pull/1075) -- [refactor:optimize discovery properties initialization.](https://github.com/Tencent/spring-cloud-tencent/pull/1079) -- [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1085) -- [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1094). -- [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1105) diff --git a/changes/changes-1.12.0.md b/changes/changes-1.12.0.md new file mode 100644 index 000000000..afe21b73a --- /dev/null +++ b/changes/changes-1.12.0.md @@ -0,0 +1,30 @@ +# Change Log +--- + +- [feature: support reactive discovery client health indicator.](https://github.com/Tencent/spring-cloud-tencent/pull/988) +- [feature: Enhance default configuration to support `application*.yaml` and `bootstrap*.yaml`.](https://github.com/Tencent/spring-cloud-tencent/pull/988) +- [feat:Remove error log from `DecodeTransferMetadataReactiveFilter`.](https://github.com/Tencent/spring-cloud-tencent/pull/991) +- [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) +- [docs:add release GitHub Action.](https://github.com/Tencent/spring-cloud-tencent/pull/1007) +- [docs:update Polaris test environment ip.](https://github.com/Tencent/spring-cloud-tencent/pull/1012) +- [fix:fix custom fallback exception.](https://github.com/Tencent/spring-cloud-tencent/pull/1022) +- [feat: sct-all package is now available as a shaded uber-jar.](https://github.com/Tencent/spring-cloud-tencent/pull/1025) +- [fix:use path parameter in `@FeignClient` for circuit-breaker.](https://github.com/Tencent/spring-cloud-tencent/pull/1028) +- [build(deps): bump guava in /spring-cloud-tencent-dependencies](https://github.com/Tencent/spring-cloud-tencent/pull/1037) +- [fix:fix reporting bug when port is -1.](https://github.com/Tencent/spring-cloud-tencent/pull/1040) +- [fix:update guava version.](https://github.com/Tencent/spring-cloud-tencent/pull/1043) +- [fix:fix circuit breaker bean load order bug when using Nacos discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/1050) +- [refactor:refactor Polaris registration.](https://github.com/Tencent/spring-cloud-tencent/pull/1057) +- [feat:added automatic optimization for dynamic config refresh type.](https://github.com/Tencent/spring-cloud-tencent/pull/1058) +- [fix:fix SCG report wrong service bug when using IP routing.](https://github.com/Tencent/spring-cloud-tencent/pull/1065) +- [fix:fix gray release examples bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1068) +- [fix:fix router label feign interceptor order.](https://github.com/Tencent/spring-cloud-tencent/pull/1071) +- [feat:added polaris weighted round robin load balancer.](https://github.com/Tencent/spring-cloud-tencent/pull/1073) +- [fix:add deregister judgment.](https://github.com/Tencent/spring-cloud-tencent/pull/1075) +- [refactor:optimize discovery properties initialization.](https://github.com/Tencent/spring-cloud-tencent/pull/1079) +- [fix:upgrade spring version.](https://github.com/Tencent/spring-cloud-tencent/pull/1085) +- [fix:Update README-zh.md](https://github.com/Tencent/spring-cloud-tencent/pull/1094). +- [feature: support Polaris configuration center extension plugin interface and support dynamic modification of log levels.](https://github.com/Tencent/spring-cloud-tencent/pull/1105) diff --git a/pom.xml b/pom.xml index ffb299d0c..fd7b595ba 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ - 1.12.0-2022.0.4 + 1.13.0-2022.0.4-SNAPSHOT 6.0.11 diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index d3df2d2f2..689440f2c 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -70,7 +70,7 @@ - 1.12.0-2022.0.4 + 1.13.0-2022.0.4-SNAPSHOT 1.14.0 From 4e210e4b6c2eccf86639db0a71c14e4da8b8ffd4 Mon Sep 17 00:00:00 2001 From: shuiqingliu Date: Tue, 12 Sep 2023 11:53:11 +0800 Subject: [PATCH 3/4] feat: bump polaris version from 1.14.0 to 1.15.0-SNAPSHOT --- spring-cloud-tencent-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index d3df2d2f2..1439e1738 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -73,7 +73,7 @@ 1.12.0-2022.0.4 - 1.14.0 + 1.15.0-SNAPSHOT 32.0.1-jre 4.9.0 1.12.19 From aa1f4a7785cdca0ab374f098232909c7257e8cb6 Mon Sep 17 00:00:00 2001 From: shuiqingliu Date: Thu, 14 Sep 2023 11:19:05 +0800 Subject: [PATCH 4/4] fix: register a destroy hook when the application event trigger if we register a destroy hook for RemoteConfigFileRepo on the class instance , the static thread pool may be terminated by the bootstrap context closing ,Therefore,it's better to register the destroy hook when the application is prepared, or when the application fails to start, in order to properly destroy resources --- .../config/PolarisConfigAutoConfiguration.java | 7 ------- .../config/PolarisContextAutoConfiguration.java | 6 ++++++ .../PolarisContextApplicationEventListener.java | 13 ++++++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) rename spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java => spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java (70%) diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java index 86396e38b..b0c212a14 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java @@ -28,13 +28,11 @@ import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType; import com.tencent.cloud.polaris.config.config.PolarisConfigProperties; import com.tencent.cloud.polaris.config.listener.PolarisConfigChangeEventListener; -import com.tencent.cloud.polaris.config.listener.PolarisConfigNonDaemonThreadStopListener; import com.tencent.cloud.polaris.config.listener.PolarisConfigRefreshOptimizationListener; import com.tencent.cloud.polaris.config.logger.PolarisConfigLoggerApplicationListener; import com.tencent.cloud.polaris.config.spring.annotation.SpringValueProcessor; import com.tencent.cloud.polaris.config.spring.property.PlaceholderHelper; import com.tencent.cloud.polaris.config.spring.property.SpringValueRegistry; -import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -65,11 +63,6 @@ public PolarisConfigChangeEventListener polarisConfigChangeEventListener() { return new PolarisConfigChangeEventListener(); } - @Bean - public PolarisConfigNonDaemonThreadStopListener polarisLongPullingStopListener(PolarisSDKContextManager polarisSDKContextManager) { - return new PolarisConfigNonDaemonThreadStopListener(polarisSDKContextManager); - } - @Bean public PolarisConfigLoggerApplicationListener polarisConfigLoggerApplicationListener() { return new PolarisConfigLoggerApplicationListener(); diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java index 1593fdd5f..febf139fd 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java @@ -25,6 +25,7 @@ import com.tencent.cloud.polaris.context.PolarisConfigModifier; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; import com.tencent.cloud.polaris.context.ServiceRuleManager; +import com.tencent.cloud.polaris.context.listener.PolarisContextApplicationEventListener; import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.client.api.SDKContext; @@ -58,4 +59,9 @@ public ModifyAddress polarisConfigModifier(PolarisContextProperties properties) public ServiceRuleManager serviceRuleManager(PolarisSDKContextManager polarisSDKContextManager) { return new ServiceRuleManager(polarisSDKContextManager.getSDKContext(), polarisSDKContextManager.getConsumerAPI()); } + + @Bean + public PolarisContextApplicationEventListener polarisContextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) { + return new PolarisContextApplicationEventListener(polarisSDKContextManager); + } } diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java similarity index 70% rename from spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java rename to spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java index 58e3f66b6..0006f71b9 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/listener/PolarisConfigNonDaemonThreadStopListener.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/listener/PolarisContextApplicationEventListener.java @@ -16,11 +16,13 @@ * */ -package com.tencent.cloud.polaris.config.listener; +package com.tencent.cloud.polaris.context.listener; import com.tencent.cloud.polaris.context.PolarisSDKContextManager; +import com.tencent.polaris.configuration.client.internal.RemoteConfigFileRepo; import org.springframework.boot.context.event.ApplicationFailedEvent; +import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.lang.NonNull; @@ -31,17 +33,22 @@ * @author shuiqingliu * @since 2023/8/29 **/ -public class PolarisConfigNonDaemonThreadStopListener implements ApplicationListener { +public class PolarisContextApplicationEventListener implements ApplicationListener { private final PolarisSDKContextManager polarisSDKContextManager; - public PolarisConfigNonDaemonThreadStopListener(PolarisSDKContextManager polarisSDKContextManager) { + public PolarisContextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) { this.polarisSDKContextManager = polarisSDKContextManager; } @Override public void onApplicationEvent(@NonNull ApplicationEvent event) { + if (event instanceof ApplicationPreparedEvent) { + RemoteConfigFileRepo.registerRepoDestroyHook(polarisSDKContextManager.getSDKContext()); + } + if (event instanceof ApplicationFailedEvent) { + RemoteConfigFileRepo.registerRepoDestroyHook(polarisSDKContextManager.getSDKContext()); //implicit invoke 'destroy' when the spring application fails to start, in order to stop non-daemon threads. polarisSDKContextManager.getSDKContext().destroy(); }