Repository navigation
SSE 연결 관리 로직 개선 - #38
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the SSE subscription logic by introducing a dedicated AvatarSseSubscribedEvent to handle initial data pushes, simplifying connection tracking by using the emitters list size instead of an AtomicInteger, and unifying connection cleanup into a single helper method. Additionally, the heartbeat interval has been reduced to 10 seconds. The review feedback highlights a potential resource leak where SseEmitter.complete() is not explicitly called when manually cleaning up failed emitters during heartbeat or send failures. It is recommended to update the cleanup function to support an optional explicit completion flag to ensure the servlet container properly releases associated resources.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the SSE subscription mechanism for avatar changes, introducing a dedicated AvatarSseSubscribedEvent, simplifying connection cleanup, and reducing the heartbeat interval to 10 seconds. Feedback on these changes highlights a potential race condition when checking and adding emitters concurrently, the risk of unexpected exceptions interrupting heartbeat and broadcast loops, and unnecessary database queries when no active emitters exist.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
✨ 작업 내용
SSE 연결 관리의 여러 문제를 개선했습니다. 새로고침 반복 시 죽은 연결이 누적되는 현상을 해결하고, 초기 구독 이벤트 처리 방식을 의미에 맞게 교체했습니다. 또한
cleanup()공통 함수를 도입해 모든 종료 경로에서 일관되게 연결이 정리되도록 했습니다.🔍 리뷰 시 참고사항
@TransactionalEventListener(AFTER_COMMIT)로 초기 데이터를 전송했는데, 이는 DB 변경 트랜잭션과 무관한 구독 요청에 트랜잭션 이벤트를 오용하는 구조였습니다.@EventListener + @Async + @Transactional(readOnly = true)로 교체해 의미를 명확히 했습니다.AtomicInteger activeConnections제거:emitters.size를 단일 소스로 사용해 카운터 불일치 가능성을 원천 차단했습니다. 최대 연결 수 검사는emitters.size >= maxConnections로 처리합니다.cleanup(emitter, reason)공통 함수:onCompletion,onTimeout,onError, send 실패, heartbeat 실패가 모두 이 함수를 통해 정리됩니다.CopyOnWriteArrayList.remove()의 원자적 boolean 반환으로 이중 정리를 방지합니다.synchronized블록 밖에서cleanup호출: 락 점유를 최소화하고 cleanup 로직을 send 실패 경로와 동일한 패턴으로 통일했습니다.handleAvatarListChanged에fallbackExecution = true추가:DeleteAllAvatarsServiceImpl이TransactionSynchronization.afterCommit()내부에서 이벤트를 발행해 활성 트랜잭션이 없는 경우에도 SSE 브로드캐스트가 동작하도록 수정했습니다.✅ 체크리스트
.env.example등) 변경이 필요한 경우 작성 또는 수정했나요?