Skip to content

[Bug] Potential memory leak in certain scenarios caused by MetadataServiceV2 #14716

@chickenlj

Description

@chickenlj

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

3.3.0

Steps to reproduce this issue

Start a regular provider and consumer, enable application-level service discovery by adding the following configuration on provider side:

dubbo:
  registry:
    register-mode: instance

Dump the heap on consumer side after it starts successfully, and find the metadata proxy instance doesn't destroy as expected.

The root reason is that MetadataServiceV2 is a stub type proxy instead of a reflection proxy type, so it does not implement Destroyable. The following check if (proxyV2 instanceof Destroyable) will never match.

public void destroy() {
          if (proxy instanceof Destroyable) {
              ((Destroyable) proxy).$destroy();
          }

          if (proxyV2 instanceof Destroyable) {
              ((Destroyable) proxyV2).$destroy();
          }

          internalModel.getServiceRepository().unregisterConsumer(consumerModel);
}

Even if MetadataServiceV2 instances failed to destroy as expected, the number of these instances won't increase with no limitation. In most cases, the number of instances of MetadataServiceV2 will stop increaseing when it reaches the number of the provider instances, that says, the maximum number depends on how many provider ips you have.

However, in certain scenarios, MetadataServiceV2 instances will keep growing as the provider instance redeploys with some Dubbo-related changes that can cause revision changes.

What you expected to happen

MetadataServiceV2 destroyed every time.

Anything else

No response

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

    Labels

    component/sdkRelated with apache/dubbojavaPull requests that update Java codetype/bugBugs to being fixed

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions