Skip to content

[Bug] The service enters an infinite loop of metadata cache cleanup under frequent registration. #15087

@QingJuBaiTang

Description

@QingJuBaiTang

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo 3.2.5
Jdk 1.8
Linux

Steps to reproduce this issue

  1. Manually perform some service registrations, such as registering one service every 10 seconds, for a total of 20 registrations.
  2. Wait for about 5 minutes, and the CPU usage will reach 100%.

What you expected to happen

Without any abnormal conditions, the CPU usage will not reach 100%.

Anything else

The reason is likely that the following code has entered an infinite loop.

// org.apache.dubbo.registry.client.AbstractServiceDiscovery
while (metadataInfos.size() > metadataInfoCacheSize) {
    AtomicReference<String> oldestRevision = new AtomicReference<>();
    AtomicReference<MetadataInfoStat> oldestStat = new AtomicReference<>();
    metadataInfos.forEach((k, v) -> {
        if (System.currentTimeMillis() - v.getUpdateTime() > metadataInfoCacheExpireTime &&
            (oldestStat.get() == null || oldestStat.get().getUpdateTime() > v.getUpdateTime())) {
            oldestRevision.set(k);
            oldestStat.set(v);
        }
    });
    if (oldestStat.get() != null) {
        metadataInfos.remove(oldestRevision.get(), oldestStat.get());
    }
}

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions