-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Naming local cache may be ignored in a rare scenario #12644
Comments
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 In my option, when |
In current implementation, |
Why |
I have tested it.
public static void main(String[] args) throws Exception {
NamingService namingService = NamingFactory.createNamingService("127.0.0.1:8848");
while (true) {
System.out.println(namingService.getAllInstances("test.1", true));
Thread.sleep(5000L);
}
}
The consumer code can still get the instance list of test.1 |
I suggest to change the method private ServiceInfo getServiceInfoBySubscribe(String serviceName, String groupName, String clusterString,
boolean subscribe) throws NacosException {
ServiceInfo serviceInfo;
if (subscribe || !EnvUtil.isDirectQueryEnabled()) {
serviceInfo = serviceInfoHolder.getServiceInfo(serviceName, groupName, clusterString);
if (null == serviceInfo || !clientProxy.isSubscribed(serviceName, groupName, clusterString)) {
try {
serviceInfo = clientProxy.subscribe(serviceName, groupName, clusterString);
} catch (NacosException ne) {
NAMING_LOGGER.warn("getServiceInfoBySubscribe subscribe failed, {}", serviceName);
// 只有订阅失败,且本地缓存也为空的情况下,才抛异常:
if (serviceInfo == null) {
throw ne;
}
}
}
} else {
serviceInfo = clientProxy.queryInstancesOfService(serviceName, groupName, clusterString, 0, false);
}
return serviceInfo;
} |
I see, it might be when first time call And when first call while starting, it must be return I think your changes is ok. just do some enhance for Method complexity, such as extract to a new method to cover the logic. |
|
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.The text was updated successfully, but these errors were encountered: