-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
If the client already disconnect, ignore this request to avoid NPE. #6175
Conversation
@@ -49,6 +49,9 @@ public EphemeralClientOperationServiceImpl(ClientManagerDelegate clientManager) | |||
public void registerInstance(Service service, Instance instance, String clientId) { | |||
Service singleton = ServiceManager.getInstance().getSingleton(service); | |||
Client client = clientManager.getClient(clientId); | |||
if (null == client || !client.isEphemeral()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abstract a method named validateClient
?
And print an warn log, I think better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print an warn log, ok.
abstract method validateClient I think is not necessary, If do it, it will be take over by util class, because need check client is null firstly. So I think it not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why take over by util class? just add one private method in EphemeralClientOperationServiceImpl is ok. it will means that check the client is valid for EphemeralClientOperationServiceImpl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this judgement not at EphemeralClientOperationServiceImpl, other place also be at same case.
Lines 222 to 235 in e0efe71
public DistroData getDatumSnapshot() { | |
List<ClientSyncData> datum = new LinkedList<>(); | |
for (String each : clientManager.allClientId()) { | |
Client client = clientManager.getClient(each); | |
if (null == client || !client.isEphemeral()) { | |
continue; | |
} | |
datum.add(client.generateSyncData()); | |
} | |
ClientSyncDatumSnapshot snapshot = new ClientSyncDatumSnapshot(); | |
snapshot.setClientSyncDataList(datum); | |
byte[] data = ApplicationUtils.getBean(Serializer.class).serialize(snapshot); | |
return new DistroData(new DistroKey(DataOperation.SNAPSHOT.name(), TYPE), data); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before you add in EphemeralClientOperationServiceImpl, only little place need this logic.
After you add, EphemeralClientOperationServiceImpl has at least four place use this logic and both need to print logs. So I think it's time to abstract a method in EphemeralClientOperationServiceImpl. If there are many place in other class need this method. We should abstract to a util class.
@@ -49,6 +49,10 @@ public EphemeralClientOperationServiceImpl(ClientManagerDelegate clientManager) | |||
public void registerInstance(Service service, Instance instance, String clientId) { | |||
Service singleton = ServiceManager.getInstance().getSingleton(service); | |||
Client client = clientManager.getClient(clientId); | |||
if (null == client || !client.isEphemeral()) { | |||
Loggers.SRV_LOG.warn("Client connection {} already disconnect", clientId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log maybe dismiss maintainer.
It can't include !client.isEphemeral()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow
common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java
Show resolved
Hide resolved
…libaba#6175) * if the client already disconnect, ignore this request to avoid npe. * unify code with DistroClientDataProcessor. * print warn info when client already disconnect. * transfer client check logic to method. * if client is not ephemeral, is illegal.
What is the purpose of the change
The client may be null after disconnect, fix it.