Browse Source

20240213: OutOfDirectMemoryError Fix

shjung 1 year ago
parent
commit
c24046f3f9

BIN
app-install/vms-comm-server.exe.20230213


+ 2 - 0
app-install/vms-comm-server.txt.jsmooth

@@ -6,6 +6,7 @@
 <JVMSearchPath>registry</JVMSearchPath>
 <JVMSearchPath>exepath</JVMSearchPath>
 <JVMSearchPath>jview</JVMSearchPath>
+<arguments>-Dio.netty.leakDetection.level=advanced</arguments>
 <currentDirectory>${EXECUTABLEPATH}</currentDirectory>
 <embeddedJar>true</embeddedJar>
 <executableName>vms-comm-server.exe</executableName>
@@ -23,6 +24,7 @@
 </skeletonProperties>
 <skeletonProperties>
 <key>URL</key>
+<value></value>
 </skeletonProperties>
 <skeletonProperties>
 <key>SingleProcess</key>

+ 1 - 1
conf/debug.properties

@@ -1,5 +1,5 @@
 #system debug setting configuration...
-#Wed Dec 20 16:41:10 KST 2023
+#Tue Feb 13 16:18:58 KST 2024
 packet-info=1001
 packet-dump=x
 system-debug=false

+ 6 - 0
src/main/java/com/its/vms/dto/TbVmsCtlrDto.java

@@ -321,6 +321,11 @@ public class TbVmsCtlrDto implements Serializable {
      * @return
      */
     public synchronized void addRegisteredCommandsTimer(VmsCommandTimeoutTask cmdTimeoutTask) {
+        if (this.netState == NET.CLOSED) {
+            log.warn("addRegisteredCommandsTimer: VMS {}, Task {} EA, OpCode {}. Already Net Closed.",
+                    cmdTimeoutTask.getCtlr().getVmsCtlrNmbr(), this.registeredCommandTimer.size(), cmdTimeoutTask.getPacket().getOpCode());
+            return;// TODO: 20240213, io.netty.util.internal.OutOfDirectMemoryError
+        }
         long timeoutSec = 1000L * 5;
         Timer timer = new Timer();
         timer.schedule(cmdTimeoutTask, timeoutSec);
@@ -378,6 +383,7 @@ public class TbVmsCtlrDto implements Serializable {
             VmsCommandTimeoutTask cmdTimeoutTask = new VmsCommandTimeoutTask(this, packet, retryCnt);
             addRegisteredCommandsTimer(cmdTimeoutTask);
         }
+        sendBuffer = null;// TODO: 20240213, io.netty.util.internal.OutOfDirectMemoryError
         return result;
     }
 

+ 2 - 0
src/main/java/com/its/vms/esb/service/EsbVmsTcpService.java

@@ -82,6 +82,7 @@ public class EsbVmsTcpService {
             this.mapper.insertVmsShortMsg(data);
             EsbVmsTcpClient.closeSocket(socket, 0);
         }
+        cmdBuffer = null; // TODO: 20230213
         return result;
     }
 
@@ -135,6 +136,7 @@ public class EsbVmsTcpService {
                     sendResult.setSendDt("");
                 }
                 this.mapper.updateVmsShortMsgResult(sendResult);
+                cmdBuffer = null; // TODO: 20230213
             }
         }
         catch (Exception e) {

+ 7 - 1
src/main/java/com/its/vms/xnettcp/vms/VmsTcpCommServerService.java

@@ -95,10 +95,16 @@ public class VmsTcpCommServerService {
 
         serverBootstrap.option(ChannelOption.AUTO_READ, true);
         serverBootstrap.option(ChannelOption.SO_BACKLOG, config.getBackLog());
-        serverBootstrap.option(ChannelOption.SO_RCVBUF, config.getRcvBuf());
         serverBootstrap.option(ChannelOption.SO_REUSEADDR, true);
         serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeoutSeconds()*1000);
 
+        // TODO: 20240213 - START
+        //serverBootstrap.option(ChannelOption.SO_RCVBUF, config.getRcvBuf());
+        serverBootstrap.option(ChannelOption.SO_SNDBUF, 1024 * 32768);
+        serverBootstrap.option(ChannelOption.SO_RCVBUF, 1024 * 32768);
+        serverBootstrap.option(ChannelOption.TCP_NODELAY, true);
+        // TODO: 20240213 - END
+
         serverBootstrap.childOption(ChannelOption.SO_LINGER, 0);           // 4way-handshake 비활성
         serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, false);    // KEEPALIVE 비활성(활성: true)
         serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, true);     // 소켓 재사용

+ 1 - 0
src/main/java/com/its/vms/xnettcp/vms/codec/VmsTcpServerEncoder.java

@@ -55,6 +55,7 @@ public class VmsTcpServerEncoder extends MessageToByteEncoder<Object> {
             ByteBuffer buffer = (ByteBuffer) msg;
             byte[] sendBytes = buffer.array();
             outByteBuf.writeBytes(sendBytes);
+            buffer = null;  // TODO: 20240213
             log.info("SEND: VMS {}, VmsTcpServerEncoder.encode: {} Bytes.", obj.getVmsCtlrNmbr(), sendBytes.length);
         }
         finally {

+ 2 - 1
src/main/java/com/its/vms/xnettcp/vms/handler/VmsServerIdleStateHandler.java

@@ -147,11 +147,12 @@ public class VmsServerIdleStateHandler extends ChannelDuplexHandler {
         // 이곳 핸들러에서 종료되는 경우는 채널연결이 인증되지 않는 경우이므로 그냥 종료시키면 된다.
         String ipAddress = NettyUtils.getRemoteIpAddress(ctx.channel());
         MDC.put("id", this.vmsObj.getLogKey());
-        log.error("VmsServerIdleStateHandler.--exceptionCaught: {}, {}, Exception: {}", ipAddress, ctx.channel().toString(), cause);
+        log.error("VmsServerIdleStateHandler.--exceptionCaught: {}, {}, Exception: {}", ipAddress, ctx.channel().toString(), cause.toString());
         VmsServerIdleStateHandler.disconnectChannel(this.vmsObj, ctx.channel());
         MDC.remove(this.vmsObj.getLogKey());
         MDC.clear();
         super.exceptionCaught(ctx, cause);
+        ctx.channel().close();  // TODO: 20240213, io.netty.util.internal.OutOfDirectMemoryError
     }
 
     public static void disconnectChannel(TbVmsCtlrDto AObj, Channel channel) {

+ 1 - 1
src/main/java/com/its/vms/xnettcp/vms/handler/VmsServerIdleStatePacketHandler.java

@@ -77,7 +77,7 @@ public class VmsServerIdleStatePacketHandler extends IdleStateHandler {
         if (obj != null) {
             MDC.put("id", obj.getLogKey());
         }
-        log.error("DsrcAsn1ServerIdleStatePacketHandler.---exceptionCaught: {}, {}, Exception: {}", ipAddress, ctx.channel().toString(), cause);
+        log.error("VmsServerIdleStatePacketHandler.---exceptionCaught: {}, {}, Exception: {}", ipAddress, ctx.channel().toString(), cause.toString());
         VmsServerIdleStatePacketHandler.disconnectChannel(obj, ctx.channel());
         super.exceptionCaught(ctx, cause);
         if (obj != null) {

+ 2 - 1
src/main/java/com/its/vms/xnettcp/vms/handler/VmsServerPacketInboundHandler.java

@@ -56,7 +56,8 @@ public class VmsServerPacketInboundHandler extends ChannelInboundHandlerAdapter
             }
             byte[] packets = new byte[readableBytes];
             byteBuf.readBytes(packets);
-           framePacket = new VmsResFramePacket(vmsObj, packets, packets.length);
+            framePacket = new VmsResFramePacket(vmsObj, packets, packets.length);
+            byteBuf.release(); // TODO: 20230213
         }
         this.tcpServerRecvDataProcess.add(new TcpServerRecvData(TcpServerRecvData.DATA_TYPE_RES_PACKET, framePacket.getVmsObj(), ctx, framePacket));
     }