update异常后删除连接

This commit is contained in:
2023-11-06 13:20:07 +08:00
parent 65dbee64a1
commit df8f916c88
2 changed files with 20 additions and 0 deletions

View File

@@ -180,6 +180,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
if (flag) {
log.error("发生异常关闭链接channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
ctx.channel().close();
close(channelId);
}
}
}
@@ -201,6 +203,16 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
}
log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, CHANNEL_MAP.size());
ctx.channel().close();
close(channelId);
}
}
private void close(ChannelId channelId) {
// 删除桩编号和channel的关系
PileChannelEntity.removeByChannelId(channelId.asLongText());
// 删除连接
CHANNEL_MAP.remove(channelId);
}
}