Conversation
| @@ -0,0 +1,55 @@ | |||
| package com.project200.common.utils | |||
There was a problem hiding this comment.
Core network module로 빼는건 어떤가요
There was a problem hiding this comment.
좋은 생각인 것 같습니다!
추후 모듈로 분리하는 pr 따로 올리겠습니다
| CoroutineScope(Dispatchers.IO).launch { | ||
| networkMonitor.networkState.collect { isConnected -> | ||
| if (isConnected && isUserInChatRoom) { | ||
| retryCount = 0 |
There was a problem hiding this comment.
Retry count가 thread safe한가요?
There was a problem hiding this comment.
지적해주신대로 retryCount가 현재 서로 다른 스레드에서 동시에 접근하고 있습니다.
- NetworkMonitor의 Flow 콜백
- WebSocketListener의 이벤트
- handleConnectionFailure 코루틴
동시 접근 시에 경쟁 상태가 되는 문제가 발생하는 것을 확인했습니다.
AtomicInteger를 사용하여 retryCount가 일관적으로 유지되도록 수정했습니다.
5a9560f
|
|
||
| // 소켓 연결 | ||
| val wsUrl = | ||
| if (BuildConfig.DEBUG) { |
| * 소켓 연결 처리 | ||
| */ | ||
| private fun connectSocketInternal(chatRoomId: Long) { | ||
| if (webSocket != null) return |
There was a problem hiding this comment.
백그라운드 스레드에서 웹소켓이 연결되서 타이밍 이슈가 발생하면 어떻게 되나요
There was a problem hiding this comment.
타이밍 이슈가 발생하면 webSocket이 생성되기 전에 트리거 되면서, 여러 개의 웹소켓이 생성될 수 있을 것 같습니다.
connectionMutex.withLock을 사용하여 하나의 활성 웹소켓 인스턴스만 존재하도록 보장했습니다.
1e4787d
| private fun handleConnectionFailure(t: Throwable) { | ||
| if (!isUserInChatRoom) return | ||
| if (!networkMonitor.isCurrentlyConnected()) return | ||
|
|
There was a problem hiding this comment.
CouroutineScope cancle처리는 어떻게 되나요
There was a problem hiding this comment.
기존 코드에서 관리되지 않는 CoroutineScope를 사용하면 채팅방을 나간 뒤에도 작업이 취소되지 않는 문제가 있었습니다.
클래스 전용 repositoryScope를 정의하고, 재연결(retryJob) 및 하트비트(heartbeatJob) 작업을 별도의 Job 변수로 관리하여 cancel 할 수 있도록 수정했습니다.
4fb3d61
#️⃣연관된 이슈
#414
📝작업 내용
스크린샷 (선택)
💬리뷰 요구사항(선택)