Open nkorange opened 1 week ago
When client call subscribe api to do sub, it should throw exception when connection not ready and subscribe failed, which notify users there is some exception for connection and should retry or do other operation.
If call getAllInstances
with subscribe=true
, It can be discuss whether it should throw exception when cache exist.
In my option, when subscribe=true
, connection not ready should throw exception to notify, because users think getAllInstances
is get instances from server, not only cache.
In current implementation, subscribe=true
and Nacos server disconnected would not throw exception. Only when subscribe=true
and reconnect succeed and re-subscribe failed would the client throw exception.
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:
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):
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.