Skip to content

Commit a73c60b

Browse files
author
fishtailfu
committed
fix: fix oom risk
1 parent 1e73ac0 commit a73c60b

File tree

1 file changed

+23
-25
lines changed
  • polaris-plugins/polaris-plugins-connector/connector-nacos/src/main/java/com/tencent/polaris/plugins/connector/nacos

1 file changed

+23
-25
lines changed

polaris-plugins/polaris-plugins-connector/connector-nacos/src/main/java/com/tencent/polaris/plugins/connector/nacos/NacosConnector.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,30 @@ public CommonProviderResponse registerInstance(CommonProviderRequest req,
253253
}
254254
return response;
255255
}
256+
@Override
257+
public void deregisterInstance(CommonProviderRequest req) throws PolarisException {
258+
259+
try {
260+
NamingService service = getOrCreateNacosService(req.getNamespace()).getNamingService();
261+
if (service == null) {
262+
LOG.error("nacos client fail to lookup namingService for service {}", req.getService());
263+
return;
264+
}
265+
// 优先设置成nacos的service name,如没有再设置成req的service name
256266

267+
Instance instance = buildDeregisterNacosInstance(req);
268+
// deregister with nacos naming service
269+
service.deregisterInstance(instance.getServiceName(), nacosContext.getGroupName(),
270+
instance);
271+
LOG.info("nacos client deregister service {} success, groupName: {}, clusterName: {}, instance: {}",
272+
instance.getServiceName(), nacosContext.getGroupName(), nacosContext.getClusterName(), instance);
273+
} catch (NacosException e) {
274+
throw new RetriableException(ErrorCode.NETWORK_ERROR,
275+
String.format("nacos fail to deregister host %s:%d service %s", req.getHost(),
276+
req.getPort(),
277+
req.getService()), e);
278+
}
279+
}
257280
@Override
258281
public void heartbeat(CommonProviderRequest req) throws PolarisException {
259282
// do nothing
@@ -369,31 +392,6 @@ private Instance buildRegisterNacosInstance(CommonProviderRequest req) {
369392
return instance;
370393
}
371394

372-
@Override
373-
public void deregisterInstance(CommonProviderRequest req) throws PolarisException {
374-
375-
try {
376-
NamingService service = getOrCreateNacosService(req.getNamespace()).getNamingService();
377-
if (service == null) {
378-
LOG.error("nacos client fail to lookup namingService for service {}", req.getService());
379-
return;
380-
}
381-
// 优先设置成nacos的service name,如没有再设置成req的service name
382-
383-
Instance instance = buildDeregisterNacosInstance(req);
384-
// deregister with nacos naming service
385-
service.deregisterInstance(instance.getServiceName(), nacosContext.getGroupName(),
386-
instance);
387-
LOG.info("nacos client deregister service {} success, groupName: {}, clusterName: {}, instance: {}",
388-
instance.getServiceName(), nacosContext.getGroupName(), nacosContext.getClusterName(), instance);
389-
} catch (NacosException e) {
390-
throw new RetriableException(ErrorCode.NETWORK_ERROR,
391-
String.format("nacos fail to deregister host %s:%d service %s", req.getHost(),
392-
req.getPort(),
393-
req.getService()), e);
394-
}
395-
}
396-
397395
private String getServiceName(CommonProviderRequest req) {
398396
// nacos上注册和polaris不同的服务名时优先用nacosContext中的serviceName
399397
String serviceName = req.getService();

0 commit comments

Comments
 (0)