Skip to content

重复初始化consumer时,AbstractRegistry.register(URL url)由于url中的timestamp key始终不同,导致一直重复添加,直到内存溢出 #4587

@lamian3

Description

@lamian3
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.5.3
  • Operating System version: mac
  • Java version: 1.8.0_202

Steps to reproduce this issue

  1. java编码方式重复初始化一个没有服务提供者的consumer
while (true) {
            try {

                ReferenceConfig<INoProvider> reference = new ReferenceConfig<>(); // #1
                reference.setApplication(new ApplicationConfig("first-dubbo-client")); // #2
                reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181")); // #3
                reference.setInterface(INoProvider.class); // #4
                INoProvider noProvider = reference.get(); // #5
                noProvider.say(); // #6

                Thread.sleep(10);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

AbstractRegistry方法

public void register(URL url) {
        if (url == null) {
            throw new IllegalArgumentException("register url == null");
        }
        if (logger.isInfoEnabled()){
            logger.info("Register: " + url);
        }
        registered.add(url);
    }

AbstractRegistry内部的registered,subscribed,notified,都有重复添加的情况,因为URL的参数中带有timestamp key,每次的timestamp不同,URL的hashCode()方法并没有排除timestamp,导致能一直重复add

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions