-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Describe the bug
Naming local cache may be ignored in a rare scenario. So even when local cache is not empty, user's invocation would still get exception.
Expected behavior
If local cache is not empty, Nacos client should never throw exception.
Actually behavior
In a rare case, when local cache is not empty, user's invocation would get exception.
How to Reproduce
It's hard to reproduce but it did happen in our production environment. Here is the related logic:
in the method at getServiceInfoBySubscribe:
- first it tried to get service info from local cache;
- then it will check if local cache is null or client is not subscribed:
Usually it will work, because whenever clientProxy.isSubscribed(...)
returns false, it means the Nacos client has just reconnected to Nacos server and closed the old connection:
As new connection is ready, so the subscribe request would succeed.
But if the new connection is down immediately again so the subscribe request failed, then in the method getServiceInfoBySubscribe
, an exception will be thrown.
Desktop (please complete the following information):
- OS: [e.g. Centos]
- Version: nacos-server 2.1.2, nacos-client 2.1.2
- Module: naming
- SDK: spring-cloud-alibaba-nacos 2021.1
Additional context
I suggest to add a protection logic in the method getServiceInfoBySubscribe
, so that whenever the local cache is not empty, the remote request error or any other exception will be ignored.