Skip to content

Commit

Permalink
[BugFix] 解决重复注册时的bug。
Browse files Browse the repository at this point in the history
Signed-off-by: zhuguocheng <[email protected]>
  • Loading branch information
zhuguocheng committed Aug 22, 2021
1 parent 4985961 commit ffce1a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ public String getSekiroGroup() {
}


void overwrite(NettyClient newClient) {
Channel historyChannel = this.channel;
this.channel = newClient.channel;
if (historyChannel.isActive()) {
getLogger().error("duplicate client register old:" + historyChannel
+ " new:" + channel);
historyChannel.eventLoop().schedule((Runnable) historyChannel::close, 30, TimeUnit.SECONDS);
}
this.natClientType = newClient.natClientType;
}

public void onClientDisconnected() {
NettySekiroGroup.createOrGet(getSekiroGroup())
.safeDo(this::onClientDisconnected0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,25 @@ public void registerNettyClient(NettyClient nettyClient) {
private void registerNettyClient0(NettyClient nettyClient) {
looper.checkLooper();
NettyClient old = constantTreeMap.get(nettyClient.getConstantKey());
if (old == null) {
// BugFix. 对于已注册的手机,执行overwrite之后,
// nettyClient.doRegister方法未返回old nettyClient,却使用new nettyClient,导致invoke调用时nettyClient对象不一致,触发异常
// 解决方案: 删除old nettyClient,添加new nettyClient.
if (null != old) {
Channel historyChannel = old.getChannel();
if (historyChannel.isActive()) {
getLogger().error("duplicate client register old:" + historyChannel
+ " new:" + channel);
historyChannel.eventLoop().schedule((Runnable) historyChannel::close, 30, TimeUnit.SECONDS);
}
constantTreeMap.remove(old.getConstantKey());
clientList.remove(old);

constantTreeMap.put(nettyClient.getConstantKey(), nettyClient);
clientList.addFirst(nettyClient);
} else {
constantTreeMap.put(nettyClient.getConstantKey(), nettyClient);
clientList.addFirst(nettyClient);
return;
}
old.overwrite(nettyClient);
}

public void unregisterNettyClient(NettyClient nettyClient) {
Expand Down

0 comments on commit ffce1a5

Please sign in to comment.