Skip to content
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

Merged
merged 5 commits into from
Jun 30, 2021

Conversation

horizonzy
Copy link
Collaborator

What is the purpose of the change

The client may be null after disconnect, fix it.

@@ -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()) {
Copy link
Collaborator

@KomachiSion KomachiSion Jun 28, 2021

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

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);
}

Copy link
Collaborator

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);
Copy link
Collaborator

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()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep.

Copy link

@Moskalnazar Moskalnazar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

@KomachiSion KomachiSion added kind/refactor kind/enhancement Category issues or prs related to enhancement. labels Jun 30, 2021
@KomachiSion KomachiSion added this to the 2.0.3 milestone Jun 30, 2021
@KomachiSion KomachiSion merged commit 3fd77bc into alibaba:develop Jun 30, 2021
ZZQ001010 pushed a commit to ZZQ001010/nacos that referenced this pull request Jun 30, 2021
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Category issues or prs related to enhancement. kind/refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants