Skip to content

1.x client still requests to the server after calling unsubscribe() #7925

@gaofeihang

Description

@gaofeihang

Describe the bug
1.x client still requests to the server after calling unsubscribe(). The UpdateTask in HostReactor has no way to be stopped.

Expected behavior
After calling unsubscribe() and removing all listeners, the client stops to request to the server and stops to poll /nacos/v1/ns/instance/list. This expected behavior can reduce the QPS and the pressure of the Nacos server in some cases.

Acutally behavior
After calling unsubscribe(), the client is still polling the server. UpdateTask is scheduled in a finally block in the run() method. It can never be stopped.

How to Reproduce
Steps to reproduce the behavior:

  1. Start a 1.4.3 Nacos server
  2. Register an instance as tutorial
  3. Discover the sevice, then sleep for a while(10s)
  4. Call unsubscribe() using the same listener as subscribe() and therefore remove all listeners.
  5. Debug UpdateTask or observe the access log of the sever. The reqeusts to /nacos/v1/ns/instance/list still exist.

Desktop (please complete the following information):

  • OS: macOS Big Sur
  • Version [nacos-server 1.4.3, nacos-client 1.4.3]
  • Module [naming / nacos-client]
  • SDK [original]

Additional context
Codes for reproducing the problem.

NamingService naming = NamingFactory.createNamingService("127.0.0.1:8848");
EventListener listener = event -> {
    if (event instanceof NamingEvent) {
        System.out.println(((NamingEvent) event).getServiceName());
        System.out.println(((NamingEvent) event).getInstances());
    }
};

naming.subscribe("nacos.test.3", listener);

Thread.sleep(1000 * 10);

naming.unsubscribe("nacos.test.3", listener);

Thread.sleep(1000 * 600);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions