iohao / ioGame

无锁异步化、事件驱动架构设计的 java netty 网络编程框架; 轻量级,无需依赖任何第三方中间件或数据库就能支持集群、分布式; 适用于网络游戏服务器、物联网、内部系统及各种需要长连接的场景; 通过 ioGame 你可以很容易的搭建出一个集群无中心节点、集群自动化、分布式的网络服务器;FXGL、Unity、UE、Cocos Creator、Godot、Netty、Protobuf、webSocket、tcp、socket;java Netty 游戏服务器框架;
http://game.iohao.com
GNU Affero General Public License v3.0
834 stars 183 forks source link

AbstractUserSessions.userIdMap安全删除 #319

Closed logan2013 closed 2 months ago

logan2013 commented 2 months ago

你的问题 | 使用场景

描述你遇到的问题,或使用场景(询问框架能否满足此类需求)

删除用户跟会话的关联是否应该校验一下UserSession是否一样

SocketUserSession existSession = userIdMap.get(userId); if (existSession.equals(userSession)) { this.userIdMap.remove(userId); }

假设客户端重连后再关闭原连接

预期值

期望的预期值

实际值

实际值

复现步骤

描述复现步骤,并提供复现 demo

版本

iohao commented 2 months ago

https://github.com/iohao/ioGame/blob/2c82b55673ed83022efef35966d38b2616eebc23/external/external-netty/src/main/java/com/iohao/game/external/core/netty/session/AbstractUserSessions.java#L89-L97

logan2013 commented 2 months ago

https://github.com/iohao/ioGame/blob/2c82b55673ed83022efef35966d38b2616eebc23/external/external-netty/src/main/java/com/iohao/game/external/core/netty/session/AbstractUserSessions.java#L89-L97

看了一下,这段代码是强制下线调用的

https://github.com/iohao/ioGame/blob/2c82b55673ed83022efef35966d38b2616eebc23/external/external-core/src/main/java/com/iohao/game/external/core/broker/client/ext/impl/ForcedOfflineExternalBizRegion.java#L56-L67

https://github.com/iohao/ioGame/blob/2c82b55673ed83022efef35966d38b2616eebc23/external/external-netty/src/main/java/com/iohao/game/external/core/netty/handler/SocketUserSessionHandler.java#L66-L72

这里从ChannelHandlerContext中取出Session,然后执行removeUserSession操作,是不是可能userIdMap中的Session不一致 https://github.com/iohao/ioGame/blob/2c82b55673ed83022efef35966d38b2616eebc23/external/external-netty/src/main/java/com/iohao/game/external/core/netty/session/AbstractUserSessions.java#L55-L59

iohao commented 2 months ago

一致的