-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Description
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:
- Start a 1.4.3 Nacos server
- Register an instance as tutorial
- Discover the sevice, then sleep for a while(10s)
- Call unsubscribe() using the same listener as subscribe() and therefore remove all listeners.
- Debug UpdateTask or observe the access log of the sever. The reqeusts to
/nacos/v1/ns/instance/liststill 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);