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 beb6b95 commit 7d09195
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,35 @@ private AbstractServiceDiscovery(ApplicationModel applicationModel, String servi
}

private void removeExpiredMetadataInfo(int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
Long time = null;
Long nextTime = null;
if (metadataInfos.size() > metadataInfoCacheSize) {
List<MetadataInfoStat> values = new ArrayList<>(metadataInfos.values());
values.sort(Comparator.comparingLong(MetadataInfoStat::getUpdateTime));
for (MetadataInfoStat v : values) {
time = System.currentTimeMillis() - v.getUpdateTime();
long time = System.currentTimeMillis() - v.getUpdateTime();
if (time > metadataInfoCacheExpireTime) {
metadataInfos.remove(v.metadataInfo.getRevision(), v);
time = null;
} else {
nextTime = metadataInfoCacheExpireTime - time;
break;
}
}
}
startRefreshCache(
time == null ? metadataInfoCacheExpireTime / 2 : time,
nextTime == null ? metadataInfoCacheExpireTime / 2 : nextTime,
metadataInfoCacheSize,
metadataInfoCacheExpireTime);
}

private void startRefreshCache(long time, int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
private void startRefreshCache(long nextTime, int metadataInfoCacheSize, int metadataInfoCacheExpireTime) {
this.refreshCacheFuture = applicationModel
.getFrameworkModel()
.getBeanFactory()
.getBean(FrameworkExecutorRepository.class)
.getSharedScheduledExecutor()
.schedule(
() -> removeExpiredMetadataInfo(metadataInfoCacheSize, metadataInfoCacheExpireTime),
time,
nextTime,
TimeUnit.MILLISECONDS);
}

Expand Down

0 comments on commit 7d09195

Please sign in to comment.