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

顶号操作疑似bug #334

Closed
xujiaw opened this issue Jul 14, 2024 · 7 comments
Closed

顶号操作疑似bug #334

xujiaw opened this issue Jul 14, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@xujiaw
Copy link

xujiaw commented Jul 14, 2024

   ExternalCommunicationKit.forcedOffline(userId);
    boolean success = UserIdSettingKit.settingUserId(flowContext, userId);

按示例文档提示, 第一行代码是关闭现在已连接用户通道, 再绑定现有的连接, 但是看源码, 第一步是走的异步, 那第一步和第二步如果并发冲突后, 会不会第一步的杀通道, 把自己当前连接干掉

@iohao
Copy link
Owner

iohao commented Jul 14, 2024

forcedOffline、settingUserId 方法都是同步调用。

@xujiaw
Copy link
Author

xujiaw commented Jul 14, 2024

调用方是同步,但是看执行方,也就是对外服是异步的

@xujiaw
Copy link
Author

xujiaw commented Jul 14, 2024

@OverRide
public void removeUserSession(long userId, Object msg) {
this.ifPresent(userId, userSession -> {
ChannelFuture channelFuture = userSession.writeAndFlush(msg);
channelFuture.addListener((ChannelFutureListener) future -> {
// 回调 UserSessions 中移除对应的玩家
this.removeUserSession(userSession);
});
});
}

这个是对外服删除会话的代码,会在删除前刷新最后一条消息, 并走了监听成功再开始删

@iohao
Copy link
Owner

iohao commented Jul 14, 2024

这的确是有概率触发并发问题,如下述代码可能会将新添加的移除,从而引发问题。

private void removeUserSessionMap(SocketUserSession userSession) {
long userId = userSession.getUserId();
this.userIdMap.remove(userId);

@iohao
Copy link
Owner

iohao commented Jul 14, 2024

已修复,请使用 dev 分支尝试

private void removeUserSessionMap(SocketUserSession userSession) {
long userId = userSession.getUserId();
// #334,kv 与预期一致时才移除。(类似联合主键)
this.userIdMap.remove(userId, userSession);

@xujiaw
Copy link
Author

xujiaw commented Jul 15, 2024

好的,我试下, 现在的问题就是客户端持有的socket与服务端对应的socket不是同一个

@xujiaw
Copy link
Author

xujiaw commented Jul 15, 2024

那还有没有这样的并发问题, 就是客户端两个socket同时连过来, 那么在第一步代码ExternalCommunicationKit.forcedOffline(userId);删除历史绑定时, 谁也没删除谁,
然后到第二步绑定的时候, 是不是就是看运气谁能绑定上了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants