Skip to content

Commit 0fa7cbe

Browse files
committed
bugfix: the issue of possible infinite loop when cleaning up expired metadata info
1 parent f5fc3fe commit 0fa7cbe

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/AbstractServiceDiscovery.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,28 @@ private AbstractServiceDiscovery(ApplicationModel applicationModel, String servi
130130
}
131131

132132
public void removeExpiredMetadataInfo(int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
133+
Long time = null;
133134
if (metadataInfos.size() > metadataInfoCacheSize) {
134135
List<MetadataInfoStat> values = new ArrayList<>(metadataInfos.values());
135136
values.sort(Comparator.comparingLong(MetadataInfoStat::getUpdateTime));
136137
for (MetadataInfoStat v : values) {
137-
long time = System.currentTimeMillis() - v.getUpdateTime();
138+
time = System.currentTimeMillis() - v.getUpdateTime();
138139
if (time > metadataInfoCacheExpireTime) {
139140
metadataInfos.remove(v.metadataInfo.getRevision(), v);
140141
} else {
141-
this.refreshCacheFuture = applicationModel
142-
.getFrameworkModel()
143-
.getBeanFactory()
144-
.getBean(FrameworkExecutorRepository.class)
145-
.getSharedScheduledExecutor()
146-
.schedule(
147-
() -> removeExpiredMetadataInfo(metadataInfoCacheSize, metadataInfoCacheExpireTime),
148-
time,
149-
TimeUnit.MILLISECONDS);
150142
break;
151143
}
152144
}
153145
}
146+
this.refreshCacheFuture = applicationModel
147+
.getFrameworkModel()
148+
.getBeanFactory()
149+
.getBean(FrameworkExecutorRepository.class)
150+
.getSharedScheduledExecutor()
151+
.schedule(
152+
() -> removeExpiredMetadataInfo(metadataInfoCacheSize, metadataInfoCacheExpireTime),
153+
time == null ? metadataInfoCacheExpireTime / 2 : time,
154+
TimeUnit.MILLISECONDS);
154155
}
155156

156157
@Override

0 commit comments

Comments
 (0)