diff --git a/src/main/java/com/process/clash/adapter/realtime/socketio/SocketIoConfig.java b/src/main/java/com/process/clash/adapter/realtime/socketio/SocketIoConfig.java index 594ceca6f..1f1c11a1e 100644 --- a/src/main/java/com/process/clash/adapter/realtime/socketio/SocketIoConfig.java +++ b/src/main/java/com/process/clash/adapter/realtime/socketio/SocketIoConfig.java @@ -3,6 +3,7 @@ import com.corundumstudio.socketio.SocketIOServer; import com.corundumstudio.socketio.Transport; import com.process.clash.infrastructure.config.SocketIoProperties; +import com.process.clash.infrastructure.config.socket.SocketIoExceptionListener; import lombok.RequiredArgsConstructor; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -26,6 +27,9 @@ public SocketIOServer socketIOServer(SocketIoAuthService authService) { config.setPingTimeout(socketIoProperties.getPingTimeoutMs()); config.setTransports(Transport.WEBSOCKET); config.setAuthorizationListener(authService::authorize); + + config.setExceptionListener(new SocketIoExceptionListener()); + return new SocketIOServer(config); } } diff --git a/src/main/java/com/process/clash/infrastructure/config/socket/SocketIoExceptionListener.java b/src/main/java/com/process/clash/infrastructure/config/socket/SocketIoExceptionListener.java new file mode 100644 index 000000000..164b54ab9 --- /dev/null +++ b/src/main/java/com/process/clash/infrastructure/config/socket/SocketIoExceptionListener.java @@ -0,0 +1,20 @@ +package com.process.clash.infrastructure.config.socket; + +import com.corundumstudio.socketio.listener.DefaultExceptionListener; +import io.netty.channel.ChannelHandlerContext; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SocketIoExceptionListener extends DefaultExceptionListener { + + @Override + public boolean exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { + // Upgrade 헤더가 없는 잘못된 요청(HTTP 등)이 올 때 발생하는 로그 제어 + if (e.getMessage() != null && e.getMessage().contains("not a WebSocket request")) { + log.warn("[Socket.IO] 비정상적인 연결 시도 차단: {} (IP: {})", + e.getMessage(), ctx.channel().remoteAddress()); + return true; // 에러 전파를 여기서 중단하여 불필요한 스택 트레이스 방지 + } + return super.exceptionCaught(ctx, e); + } +} \ No newline at end of file