diff --git a/src/main/java/com/process/clash/adapter/persistence/rival/battle/BattleJpaRepository.java b/src/main/java/com/process/clash/adapter/persistence/rival/battle/BattleJpaRepository.java index 637ac2928..ed759558b 100644 --- a/src/main/java/com/process/clash/adapter/persistence/rival/battle/BattleJpaRepository.java +++ b/src/main/java/com/process/clash/adapter/persistence/rival/battle/BattleJpaRepository.java @@ -49,6 +49,7 @@ AND b.id NOT IN ( LEFT JOIN rivals r ON b.fk_rival_id = r.id WHERE (r.fk_first_user_id = :userId OR r.fk_second_user_id = :userId) AND b.battle_status NOT IN ('REJECTED', 'PENDING', 'CANCELED') + ORDER BY b.started_at DESC """, nativeQuery = true) List findByUserIdWithOutRejected(@Param("userId") Long userId); @@ -124,6 +125,7 @@ AND b.end_at < NOW() LEFT JOIN rivals r ON b.fk_rival_id = r.id WHERE (r.fk_first_user_id = :userId OR r.fk_second_user_id = :userId) AND b.battle_status = 'PENDING' + ORDER BY b.created_at DESC """, nativeQuery = true) List findPendingBattlesByUserId(@Param("userId") Long userId); } \ No newline at end of file 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 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c5a60cf6d..3ed7acdae 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,6 +2,11 @@ spring: main: web-application-type: servlet + task: + scheduling: + pool: + size: 10 # 각 스케줄러가 독립 스레드 사용 + datasource: url: ${DATABASE_URL} username: ${DATABASE_USERNAME} @@ -56,8 +61,8 @@ spring: host: ${REDIS_HOST:localhost} port: 6379 password: ${REDIS_PASSWORD} - connect-timeout: 30s - timeout: 30s + connect-timeout: 3s + timeout: 3s lettuce: pool: max-active: 50