diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebServiceManager.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebServiceManager.java index 6880f680..2ea7a0d8 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebServiceManager.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebServiceManager.java @@ -87,6 +87,16 @@ public class WebServiceManager { return userSessions.remove(userId); } + /** + * 仅当当前会话仍绑定到指定通道时才移除,避免旧连接误删新连接映射。 + */ + public static boolean removeByUserId(String userId, Channel channel) { + if (userId == null || channel == null) { + return false; + } + return userSessions.remove(userId, channel); + } + /** * 根据channelId移除会话(兼容老版本) * 时间复杂度:O(n),建议使用removeByUserId替代 diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java index ff472c39..2f968d89 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java @@ -111,7 +111,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler