Skip to content

Commit 48c4516

Browse files
authored
fix: fix lossless deregister failed when no health-check configured (#1345)
1 parent b9632fc commit 48c4516

File tree

4 files changed

+70
-74
lines changed

4 files changed

+70
-74
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
- [fix: fix the lossless provider override in multiple registries scenario](https://github.com/Tencent/spring-cloud-tencent/pull/1341)
1212
- [fix:fix nearby router properties loading bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1342)
1313
- [fix: fix grammar issues for lane router example & optimize the gateway dependency](https://github.com/Tencent/spring-cloud-tencent/pull/1343)
14-
- [refactor:let the configuration SDK context stand alone.](https://github.com/Tencent/spring-cloud-tencent/pull/1344)
14+
- [refactor:let the configuration SDK context stand alone.](https://github.com/Tencent/spring-cloud-tencent/pull/1344)
15+
- [fix: fix lossless deregister failed when no healthcheck configured](https://github.com/Tencent/spring-cloud-tencent/pull/1345)

spring-cloud-tencent-examples/lossless-example/lossless-callee-service/src/main/resources/bootstrap.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ spring:
2020
port: 28084
2121
lossless:
2222
enabled: true
23-
healthCheckPath: /lossless/callee/health
24-
healthCheckInterval: 5000
23+
port: 28084
24+
#healthCheckPath: /actuator/health
25+
#healthCheckInterval: 5000
2526
lossless:
2627
healthy:
2728
delay:
@@ -32,5 +33,4 @@ management:
3233
exposure:
3334
include:
3435
- polaris-discovery
35-
- polaris-ratelimit
36-
- polaris-config
36+
- health

spring-cloud-tencent-examples/lossless-example/lossless-nacos-callee-service/src/main/resources/bootstrap.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,15 @@ spring:
66
cloud:
77
nacos:
88
discovery:
9-
server-addr: 9.134.5.52:8848
9+
server-addr: 127.0.0.1:8848
1010
enabled: true
11-
namespace: "test1"
1211
polaris:
1312
lossless:
1413
enabled: true
15-
healthCheckPath: /lossless/nacos/callee/health
14+
port: 28085
15+
healthCheckPath: /actuator/health
1616
healthCheckInterval: 5000
1717
lossless:
1818
healthy:
1919
delay:
2020
second: 20
21-
management:
22-
endpoints:
23-
web:
24-
exposure:
25-
include:
26-
- polaris-discovery
27-
- polaris-ratelimit
28-
- polaris-config

spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisSDKContextManager.java

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -158,57 +158,7 @@ public static void innerConfigDestroy() {
158158
}
159159

160160
public void init() {
161-
if (null == serviceSdkContext) {
162-
try {
163-
// init SDKContext
164-
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
165-
() -> environment.getProperty("spring.cloud.client.ip-address"),
166-
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
167-
serviceSdkContext.init();
168-
169-
// init ProviderAPI
170-
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
171-
172-
// init losslessAPI
173-
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
174-
175-
// init ConsumerAPI
176-
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
177-
178-
// init RouterAPI
179-
routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
180-
181-
// init CircuitBreakAPI
182-
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
183-
184-
// init LimitAPI
185-
limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
186-
187-
// init AssemblyAPI
188-
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
189-
190-
// add shutdown hook
191-
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
192-
long startTimestamp = System.currentTimeMillis();
193-
long delay = 0;
194-
while (true) {
195-
if (!isRegistered || delay >= 60000) {
196-
innerDestroy();
197-
break;
198-
}
199-
else {
200-
delay = System.currentTimeMillis() - startTimestamp;
201-
}
202-
}
203-
}));
204-
LOG.info("create Polaris SDK context successfully. properties: {}", properties);
205-
}
206-
catch (Throwable throwable) {
207-
LOG.error("create Polaris SDK context failed. properties: {}", properties, throwable);
208-
throw throwable;
209-
}
210-
}
211-
161+
initService();
212162
initConfig();
213163
}
214164

@@ -225,37 +175,37 @@ public static void setConfigSDKContext(SDKContext context) {
225175
}
226176

227177
public SDKContext getSDKContext() {
228-
init();
178+
initService();
229179
return serviceSdkContext;
230180
}
231181

232182
public ProviderAPI getProviderAPI() {
233-
init();
183+
initService();
234184
return providerAPI;
235185
}
236186

237187
public LosslessAPI getLosslessAPI() {
238-
init();
188+
initService();
239189
return losslessAPI;
240190
}
241191

242192
public ConsumerAPI getConsumerAPI() {
243-
init();
193+
initService();
244194
return consumerAPI;
245195
}
246196

247197
public RouterAPI getRouterAPI() {
248-
init();
198+
initService();
249199
return routerAPI;
250200
}
251201

252202
public CircuitBreakAPI getCircuitBreakAPI() {
253-
init();
203+
initService();
254204
return circuitBreakAPI;
255205
}
256206

257207
public LimitAPI getLimitAPI() {
258-
init();
208+
initService();
259209
return limitAPI;
260210
}
261211

@@ -268,6 +218,59 @@ public SDKContext getConfigSDKContext() {
268218
return configSDKContext;
269219
}
270220

221+
public void initService() {
222+
if (null == serviceSdkContext) {
223+
try {
224+
// init SDKContext
225+
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
226+
() -> environment.getProperty("spring.cloud.client.ip-address"),
227+
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
228+
serviceSdkContext.init();
229+
230+
// init ProviderAPI
231+
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
232+
233+
// init losslessAPI
234+
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
235+
236+
// init ConsumerAPI
237+
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
238+
239+
// init RouterAPI
240+
routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
241+
242+
// init CircuitBreakAPI
243+
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
244+
245+
// init LimitAPI
246+
limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
247+
248+
// init AssemblyAPI
249+
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
250+
251+
// add shutdown hook
252+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
253+
long startTimestamp = System.currentTimeMillis();
254+
long delay = 0;
255+
while (true) {
256+
if (!isRegistered || delay >= 60000) {
257+
innerDestroy();
258+
break;
259+
}
260+
else {
261+
delay = System.currentTimeMillis() - startTimestamp;
262+
}
263+
}
264+
}));
265+
LOG.info("create Polaris SDK context successfully. properties: {}", properties);
266+
}
267+
catch (Throwable throwable) {
268+
LOG.error("create Polaris SDK context failed. properties: {}", properties, throwable);
269+
throw throwable;
270+
}
271+
}
272+
}
273+
271274
public void initConfig() {
272275
// get modifiers for configuration.
273276
List<PolarisConfigModifier> configModifierList = new ArrayList<>();

0 commit comments

Comments
 (0)