Copilot commented on code in PR #15915:
URL: https://github.com/apache/dubbo/pull/15915#discussion_r2644787182
##########
dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java:
##########
@@ -473,26 +473,30 @@ private boolean isAdminProtocol(URL url) {
private void scheduleServiceNamesLookup(final URL url, final
NacosAggregateListener listener) {
if (scheduledExecutorService == null) {
- scheduledExecutorService =
Executors.newSingleThreadScheduledExecutor();
- scheduledExecutorService.scheduleAtFixedRate(
- () -> {
- Set<String> serviceNames = getAllServiceNames();
- filterData(serviceNames, serviceName -> {
- boolean accepted = false;
- for (String category : ALL_SUPPORTED_CATEGORIES) {
- String prefix = category +
SERVICE_NAME_SEPARATOR;
- if (serviceName != null &&
serviceName.startsWith(prefix)) {
- accepted = true;
- break;
- }
- }
- return accepted;
- });
- doSubscribe(url, listener, serviceNames);
- },
- LOOKUP_INTERVAL,
- LOOKUP_INTERVAL,
- TimeUnit.SECONDS);
+ synchronized (this) {
+ if (scheduledExecutorService == null) {
+ scheduledExecutorService =
Executors.newSingleThreadScheduledExecutor();
Review Comment:
Potential race condition. This assignment to [scheduledExecutorService](1)
is visible to other threads before the subsequent statements are executed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]