Skip to content

Commit

Permalink
修复网络异常断开、重连的时候用户在线列表变成下线的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
夜色 committed Jun 22, 2018
1 parent faf1055 commit dd38cb0
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ void on(ConnectionCloseEvent event) {
String userId = context.userId;
if (userId == null) return;

EventBus.post(new UserOfflineEvent(event.connection, userId));
int clientType = context.getClientType();
LocalRouter localRouter = routers.getOrDefault(userId, EMPTY).get(clientType);
if (localRouter == null) return;

String connId = connection.getId();
//2.检测下,是否是同一个链接, 如果客户端重连,老的路由会被新的链接覆盖
if (connId.equals(localRouter.getRouteValue().getId())) {
//3.删除路由
//3. 删除路由
routers.getOrDefault(userId, EMPTY).remove(clientType);
//4. 发送用户下线事件, 只有老的路由存在的情况下才发送,因为有可能又用户重连了,而老的链接又是在新连接之后才断开的
//这个时候就会有问题,会导致用户变成下线状态,实际用户应该是在线的。
EventBus.post(new UserOfflineEvent(event.connection, userId));
LOGGER.info("clean disconnected local route, userId={}, route={}", userId, localRouter);
} else { //如果不相等,则log一下
LOGGER.info("clean disconnected local route, not clean:userId={}, route={}", userId, localRouter);
Expand Down

0 comments on commit dd38cb0

Please sign in to comment.