Skip to content

Conversation

@NCookies
Copy link
Collaborator

@NCookies NCookies commented Aug 19, 2025

작업 내용

  • 일정 시간동안 아무런 데이터가 오가지 않으면 웹소켓의 메시지 브로커(ActiveMQ)가 자동으로 연결을 끊어버림
  • heart beat 기능을 애플리케이션 단에 직접 구현함
  • idle timeout 이슈를 해결하기 위해 activemq가 실행되고 있는 ec2 인스턴스의 인바운드 규칙을 편집함

참고 사항

Summary by CodeRabbit

  • 새 기능
    • 실시간 알림/메시징 연결의 안정성을 강화했습니다. 서버가 주기적으로 keep-alive 신호를 전송하여 비활성 시간에도 연결이 끊기지 않도록 해, 라이브 업데이트 지연·예기치 않은 연결 종료를 줄입니다.
    • 장시간 브라우저 탭 유지 시에도 STOMP 기반 주제 구독이 더 안정적으로 유지됩니다.

- 일정 시간동안 아무런 데이터가 오가지 않으면 웹소켓의 메시지 브로커(ActiveMQ)가 자동으로 연결을 끊어버림
- heart beat 기능을 애플리케이션 단에 직접 구현함
- idle timeout 이슈를 해결하기 위해 activemq가 실행되고 있는 ec2 인스턴스의 인바운드 규칙을 편집함
@NCookies NCookies self-assigned this Aug 19, 2025
@NCookies NCookies added the bug Something isn't working label Aug 19, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

새 Spring 컴포넌트 StompKeepAliveScheduler를 추가하여, @scheduled(fixedDelay=15000)로 15초 간격으로 STOMP 주제 /topic/keep-alive 에 "ping" 메시지를 SimpMessagingTemplate.convertAndSend로 전송합니다. ActiveMQ TTL(20초)보다 짧게 설정되었음이 주석으로 명시되었습니다.

Changes

Cohort / File(s) Summary
스케줄러/Keep-Alive 송신 추가
src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java
@component 클래스 추가. 생성자 주입으로 SimpMessagingTemplate 사용. @scheduled(fixedDelay=15000) 메서드 sendKeepAliveMessage()에서 "/topic/keep-alive"로 "ping" 전송. 주석에 ActiveMQ TTL(20s) 대비 15s 설정 이유 기재.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant CRON as Spring Scheduler
    participant SKS as StompKeepAliveScheduler
    participant SMT as SimpMessagingTemplate
    participant BROKER as STOMP Broker
    participant SUB as Subscribers

    Note over CRON: fixedDelay = 15s (실행 종료 후 15초 대기)
    CRON->>SKS: 트리거 sendKeepAliveMessage()
    SKS->>SMT: convertAndSend("/topic/keep-alive", "ping")
    SMT->>BROKER: STOMP 전송
    BROKER-->>SUB: 메시지 전달 ("ping")
    Note over BROKER,SUB: TTL 20s 내 keep-alive 수신
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement

Suggested reviewers

  • pokerbearkr
  • thezz9

Poem

(•̀ᴗ•́)و ̑̑ ʕ•̀ω•́ʔ✧
토픽 위로 핑, 또 한 번의 점프!
스프링의 북소리 열다섯 초마다 둥둥—
브로커 숲에 메아리치는 작은 발자국.
“잊지 마요, 여기 있어요!”
토끼는 귀를 깜빡, 연결은 쫀쫀.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/socket-connection-timeout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java (3)

16-18: 간격을 프로퍼티로 노출하고 fixedRate+initialDelay로 드리프트/GC 지연을 완충하세요.

현재 fixedDelay=15초는 브로커 타임아웃(주석 상 20초) 대비 버퍼가 얇습니다. GC/네트워크 지연이 끼면 간헐적으로 20초를 넘길 수 있습니다. fixedRate와 초기 지연을 두고, 값을 프로퍼티로 조정 가능하게 하는 것을 권장합니다.

아래와 같이 주석을 더 정확히 하고, 스케줄 애노테이션을 프로퍼티 기반으로 바꾸는 것을 제안합니다.

-	// 15초마다 실행 (ActiveMQ TTL인 20초보다 짧게 설정)
-	@Scheduled(fixedDelay = 15000)
+	// 기본 15초 간격(브로커 inactivity timeout보다 짧게), 초기 지연 5초. 프로퍼티로 조정 가능
+	@Scheduled(
+		fixedRateString = "${stomp.keepalive.interval-ms:15000}",
+		initialDelayString = "${stomp.keepalive.initial-delay-ms:5000}"
+	)

참고:

  • fixedRate는 실행 시작 시각 기준으로 주기 유지 → 일시 지연 영향 완화
  • 운영 환경별로 간격을 빠르게 조정 가능

19-20: 브로커 릴레이 프리픽스와 접근 제어를 점검하세요.

  • 이 메시지가 ActiveMQ로 실제 전달되어야 효과가 있으므로, 메시지 브로커 설정에서 enableStompBrokerRelay("/topic", "/queue") 등으로 /topic이 릴레이 프리픽스로 설정되어 있는지 확인이 필요합니다. SimpleBroker만 쓰고 있다면 ActiveMQ 연결 유지에 영향을 주지 않습니다.
  • 클라이언트에게 불필요한 "ping"이 전달되지 않도록, 메시지 보안 설정에서 해당 토픽 구독을 차단하는 것도 고려해 주세요(운영 노이즈 방지).

예시(스프링 메시지 보안 사용 시):

@Override
protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
  messages
    .simpSubscribeDestMatchers("/topic/keep-alive").denyAll()  // 내부 전용
    .anyMessage().authenticated();
}

18-20: 전송 실패 추적을 위한 가벼운 로그/예외 처리 제안(선택).

운영 트러블슈팅을 위해 DEBUG/TRACE 로그를 남기고, 드물게 발생 가능한 MessageDeliveryException 등을 캐치해 경고 로그로 남기는 것을 권장합니다.

예시:

// 클래스 필드/임포트(예시)
// import lombok.extern.slf4j.Slf4j;
// @Slf4j
public void sendKeepAliveMessage() {
  try {
    this.messagingTemplate.convertAndSend("/topic/keep-alive", "ping");
    // log.trace("STOMP keep-alive sent");
  } catch (Exception e) {
    // log.warn("STOMP keep-alive send failed", e);
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d712e78 and d5e7c2d.

📒 Files selected for processing (1)
  • src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
src/main/java/org/ezcode/codetest/infrastructure/scheduler/StompKeepAliveScheduler.java (2)

7-14: LGTM: 컴포넌트 등록과 생성자 주입이 명확합니다.

  • @component + 생성자 주입 + final 필드 구성은 적절합니다. 불변 필드로 스레드 안정성 측면에서도 좋습니다.

1-6: @EnableScheduling이 이미 활성화되어 있습니다

src/main/java/org/ezcode/codetest/CodetestApplication.java 11번째 줄에 @EnableScheduling이 선언되어 있어 스케줄링이 정상적으로 동작합니다. 별도의 추가 설정 클래스는 필요 없습니다.

@pokerbearkr pokerbearkr merged commit 0f7bf33 into dev Oct 20, 2025
2 checks passed
@pokerbearkr pokerbearkr deleted the fix/socket-connection-timeout branch October 20, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants