Skip to content

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

Closed
@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

Activity

tswstarplanet

tswstarplanet commented on Jul 17, 2019

@tswstarplanet
Contributor

请问什么场景,需要一直对同一个接口不断地生成reference呢?

lamian3

lamian3 commented on Jul 17, 2019

@lamian3
Author

请问什么场景,需要一直对同一个接口不断地生成reference呢?

proxy的一个系统,使用配置去动态初始化客户端进行调用,所以第三方调用就会去尝试初始化对应的consumer,目前,我们是发现了这种情况,自己把没有provider的服务,在配置中删除,但这个我觉得应该是个bug,因为本身AbstractRegistry用了set集合,也是希望做去重处理的吧

lamian3

lamian3 commented on Jul 17, 2019

@lamian3
Author

请问什么场景,需要一直对同一个接口不断地生成reference呢?

AbstractRegistry add完成之后,也因为timestamp的原因,其实是没有地方能够去remove掉的

tswstarplanet

tswstarplanet commented on Jul 18, 2019

@tswstarplanet
Contributor

嗯。这感觉也算一个bug,我也在看这个。但是你为什么要每个consumer都要新建一个新的RegistryConfig呢?都用同一个不行吗?

lamian3

lamian3 commented on Jul 19, 2019

@lamian3
Author

嗯。这感觉也算一个bug,我也在看这个。但是你为什么要每个consumer都要新建一个新的RegistryConfig呢?都用同一个不行吗?

初始化的代码是我直接从官方摘下来的,没做改动,刚把RegistryConfig提出来用一个,结果还是一样的。

added this to the 2.7.5 milestone on Aug 1, 2019
beiwei30

beiwei30 commented on Aug 1, 2019

@beiwei30
Member

target to 2.7.5, is there anyone willing to provide a pull request?

tswstarplanet

tswstarplanet commented on Aug 2, 2019

@tswstarplanet
Contributor

target to 2.7.5, is there anyone willing to provide a pull request?

I will try to do this.

modified the milestones: 2.7.5, 2.7.6 on Dec 30, 2019
modified the milestones: 2.7.6, 2.7.7 on Mar 16, 2020
modified the milestones: 2.7.7, 2.7.8 on Apr 27, 2020

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

    Participants

    @hengyunabc@tswstarplanet@lamian3@chickenlj@beiwei30

    Issue actions

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