Skip to content

[TSK-57] 실시간 여석 로직 개선 with Codex#273

Open
3Juhwan wants to merge 2 commits intomainfrom
codex/refactor-sseemitterstorage-for-better-resource-handling
Open

[TSK-57] 실시간 여석 로직 개선 with Codex#273
3Juhwan wants to merge 2 commits intomainfrom
codex/refactor-sseemitterstorage-for-better-resource-handling

Conversation

@3Juhwan
Copy link
Copy Markdown
Member

@3Juhwan 3Juhwan commented Feb 17, 2026

변경사항

  • 필드 타입을 ConcurrentMap<String, SseEmitter>로 변경하고, 실제 구현체로 ConcurrentHashMap을 유지하여 동시성 의도와 구현을 일치시켰습니다.
  • 기존 TODO 형태의 주석을 제거하고, 다음 내용을 설명하는 구체적인 Javadoc을 추가했습니다.
    • ConcurrentHashMap을 사용하는 이유
    • getEmitters() / getUserTokens()가 스냅샷 ArrayList 복사본을 반환하는 이유
  • 콜백 안전 제거를 위한 헬퍼(removeIfSameEmitter(...))를 유지 및 연결하고,
    • emitter 교체/제거 시 로그를 통해 동작을 명확히 남기도록 했습니다.
  • getEmitter()Optional.ofNullable(emitters.get(token)) 형태로 단순화했습니다.
  • TrackableSseEmitter를 활용한 SseEmitterStorageTest를 추가하여 다음을 검증합니다.
    • 이전 emitter의 콜백이 새 emitter를 제거하지 않음을 보장
    • 현재 emitter에서 발생한 error 콜백은 정상적으로 해당 emitter를 제거함을 보장

참고

  • ai native 전환을 위한 초석으로, 웹 codex를 활용하여 코드 한 줄 입력하지 않고 PR을 올렸습니다.
  • PR 작성까지 codex가 해주는데 제목과 코멘트만 수정했습니다.

@3Juhwan 3Juhwan self-assigned this Feb 17, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 17, 2026

Test Results

153 tests   153 ✅  25s ⏱️
 36 suites    0 💤
 36 files      0 ❌

Results for commit 09a65d2.

♻️ This comment has been updated with latest results.

@3Juhwan 3Juhwan changed the title Clarify SSE emitter map implementation and add focused storage tests [TSK-57] 실시간 여석 로직 개선 with Codex Feb 17, 2026
@3Juhwan 3Juhwan removed the codex label Feb 17, 2026
Comment on lines -30 to -33
sseEmitter.onTimeout(() -> {
emitters.remove(token);
log.debug("[SSE] 연결이 타임아웃으로 종료되었습니다. 현재 연결 수: {}", emitters.size());
});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

아래 코드와 비교해보면 emitters.remove(token) -> emitters.remove(token, expectedEmitter) 로 변경했어요.
remove 에 key,value까지 정확히 맞는 경우에만 삭제합니다. 이로서 다음 케이스를 방지할 수 있는데요.

  • T1: A 연결 등록 (token -> A)
  • T2: 같은 token으로 B 재연결 (token -> B로 교체)
  • T3: A의 timeout/completion 콜백이 지연 후 실행
  • T4: 콜백이 무조건 remove(token)이면 현재 값(B)도 제거됨
  • T5: 서버 입장에서는 최신 연결(B)이 사라져 전파 누락/연결수 오표시 가능


if (previousEmitter != null) {
log.debug("[SSE] 기존 연결을 교체합니다. token: {}", token);
previousEmitter.completeWithError(new IllegalStateException("SSE emitter replaced by newer connection."));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
previousEmitter.completeWithError(new IllegalStateException("SSE emitter replaced by newer connection."));
previousEmitter.complete();

로 수정하는 게 낫겠군요~

@3Juhwan 3Juhwan marked this pull request as ready for review February 17, 2026 16:22
- SSE 커넥션 재연결 시, 이전 emitter는 complete 처리
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant