Skip to content

Commit

Permalink
fix: the polaris config relation non-daemon thread should stop when a…
Browse files Browse the repository at this point in the history
…pplication fails to start. (#1100)

Co-authored-by: Haotian Zhang <[email protected]>
  • Loading branch information
shuiqingliu and SkyeBeFreeman authored Sep 14, 2023
1 parent bfccf33 commit 6a4e50b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change Log
---

- [fix:the polaris config relation non-daemon thread should stop when application fails to start.](https://github.com/Tencent/spring-cloud-tencent/pull/1100)
- [fix:fix feign url bug when using sleuth.](https://github.com/Tencent/spring-cloud-tencent/pull/1096)
- [fix: dynamic routing using cookies.](https://github.com/Tencent/spring-cloud-tencent/pull/1097)
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import com.tencent.cloud.polaris.config.annotation.PolarisConfigAnnotationProcessor;
import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.listener.PolarisConfigApplicationEventListener;
import com.tencent.cloud.polaris.config.listener.PolarisConfigChangeEventListener;
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;
Expand Down Expand Up @@ -68,7 +70,6 @@ public PolarisConfigLoggerApplicationListener polarisConfigLoggerApplicationList
return new PolarisConfigLoggerApplicationListener();
}


@Bean
@Primary
@ConditionalOnReflectRefreshType
Expand Down Expand Up @@ -121,5 +122,10 @@ public PolarisConfigRefreshScopeAnnotationDetector polarisConfigRefreshScopeAnno
public PolarisConfigRefreshOptimizationListener polarisConfigRefreshOptimizationListener() {
return new PolarisConfigRefreshOptimizationListener();
}

@Bean
public PolarisConfigApplicationEventListener polarisContextApplicationEventListener(PolarisSDKContextManager polarisSDKContextManager) {
return new PolarisConfigApplicationEventListener(polarisSDKContextManager);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 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;

/*
* Polaris config non-daemon thread stop listener
*
* @author shuiqingliu
* @since 2023/8/29
**/
public class PolarisConfigApplicationEventListener implements ApplicationListener<ApplicationEvent> {

private final PolarisSDKContextManager polarisSDKContextManager;

public PolarisConfigApplicationEventListener(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();
}
}

}

0 comments on commit 6a4e50b

Please sign in to comment.