Skip to content

Commit

Permalink
bugfix: the issue of possible infinite loop when cleaning up expired …
Browse files Browse the repository at this point in the history
…metadata info
  • Loading branch information
funky-eyes committed Jan 22, 2025
1 parent f5fc3fe commit 0fa7cbe
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,28 @@ private AbstractServiceDiscovery(ApplicationModel applicationModel, String servi
}

public void removeExpiredMetadataInfo(int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
Long time = null;
if (metadataInfos.size() > metadataInfoCacheSize) {
List<MetadataInfoStat> values = new ArrayList<>(metadataInfos.values());
values.sort(Comparator.comparingLong(MetadataInfoStat::getUpdateTime));
for (MetadataInfoStat v : values) {
long time = System.currentTimeMillis() - v.getUpdateTime();
time = System.currentTimeMillis() - v.getUpdateTime();
if (time > metadataInfoCacheExpireTime) {
metadataInfos.remove(v.metadataInfo.getRevision(), v);
} else {
this.refreshCacheFuture = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getSharedScheduledExecutor()
.schedule(
() -> removeExpiredMetadataInfo(metadataInfoCacheSize, metadataInfoCacheExpireTime),
time,
TimeUnit.MILLISECONDS);
break;
}
}
}
this.refreshCacheFuture = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getSharedScheduledExecutor()
.schedule(
() -> removeExpiredMetadataInfo(metadataInfoCacheSize, metadataInfoCacheExpireTime),
time == null ? metadataInfoCacheExpireTime / 2 : time,
TimeUnit.MILLISECONDS);
}

@Override
Expand Down

0 comments on commit 0fa7cbe

Please sign in to comment.