Переглянути джерело

synchronize channel map setting

shjung 1 тиждень тому
батько
коміт
97bf5b49f7

+ 0 - 1
conf/tsi-comm-server.pid

@@ -1 +0,0 @@
-47029

+ 6 - 6
tsi-comm-server/src/main/java/com/tsi/comm/server/tcp/codec/CvimServerByteBufMessageDecoder.java

@@ -84,18 +84,18 @@ public class CvimServerByteBufMessageDecoder extends MessageToMessageDecoder<Byt
 
                 // 중복 로그인 체크
                 Channel oldChannel = nodeVo.getChannel();
-                if (oldChannel != null && oldChannel.isActive()) {
+                if (oldChannel != null && oldChannel.isActive() && oldChannel != ctx.channel()) {
                     // 중복 연결 로깅
-                    if (oldChannel != ctx.channel()) {
-                        this.alarmManager.alarmDupConnect(nodeVo.getNodeId(), nodeVo.getIpAddr(), remoteIpAddress);
-                        oldChannel.close();
-                    }
+                    this.alarmManager.alarmDupConnect(nodeVo.getNodeId(), nodeVo.getIpAddr(), remoteIpAddress);
+                    oldChannel.close();
                 }
 
                 // first connection, save node information to channel attribute map
                 // 채널 맵에 채널에 대한 노드정보를 저장한다.
                 // 채널 목록에 접속 정보 등록
-                nodeVo.setConnect(ctx.channel());
+                synchronized (nodeVo) {
+                    nodeVo.setConnect(ctx.channel());
+                }
                 this.sessionManager.addChannel(ctx.channel(), nodeVo);
                 TsiChannelSession.objectRegistered(nodeVo, remoteIpAddress);
 

+ 10 - 9
tsi-comm-server/src/main/java/com/tsi/comm/server/tcp/handler/CvimServerInboundMessageHandler.java

@@ -100,16 +100,17 @@ public class CvimServerInboundMessageHandler extends ChannelInboundHandlerAdapte
 
             this.sessionManager.removeChannel(ctx.channel());
             ctx.channel().attr(TsiSessionManager.TSI_NODE_ATTRIBUTE_KEY).set(null);
-
             this.queueDistributorService.releaseQueue(nodeVo);    // 작업큐를 할당을 해제한다.
-            if (nodeVo.getChannel() == ctx.channel()) {
-                // 현재 비활성화되는 채널이 nodeVo에 등록된 활성 채널과 동일한 경우에만
-                nodeVo.setConnect(null);
-                log.info("channelInactive: {}, {}, sessions: {}", nodeVo.getNodeId(), remoteIpAddr, sessions);
-            }
-            else {
-                // 새로운 연결에 의해 강제로 종료되었음
-                log.warn("channelInactive: {}, {}, sessions: {}, Duplicate Connected.", nodeVo.getNodeId(), remoteIpAddr, sessions);
+
+            synchronized (nodeVo) {
+                if (nodeVo.getChannel() == ctx.channel()) {
+                    // 현재 비활성화되는 채널이 nodeVo에 등록된 활성 채널과 동일한 경우에만
+                    nodeVo.setConnect(null);
+                    log.info("channelInactive: {}, {}, sessions: {}", nodeVo.getNodeId(), remoteIpAddr, sessions);
+                } else {
+                    // 새로운 연결에 의해 강제로 종료되었음
+                    log.warn("channelInactive: {}, {}, sessions: {}, Duplicate Connected.", nodeVo.getNodeId(), remoteIpAddr, sessions);
+                }
             }
         }
         else {