Skip to content

Conversation

@sehee123
Copy link
Collaborator

@sehee123 sehee123 commented Jul 21, 2025

🛰️ Issue Number

🪐 작업 내용

  • 새로고침, 브라우저 닫기 등 비정상 disconnect에 대한 보완
  • 기존에 Room에서 관리 되던 Map<UserId, SessionId> map 을 새로 만든 SessionService에서 관리하도록 변경

전체적인 흐름

  1. disconnect 이벤트리스너에서 연결끊김을 감지한 후 roomPlayer정보를 disconnect로 변경

  2. 5초의 유예시간 후 connected가 되었으면 ~님이 재연결 되었습니다. systemNotice 전송 (추후 개인에게만 전송으로 변경예정)

  3. 5초 후에도 disconnected 라면 게임 진행중이 아니면 exit 처리(이미 exit 처리가 된 정상로직이 아닐경우를 판단하여 처리)

  4. connect 이벤트 리스너에서는 새로 연결된 sessionIdput

  5. subscribe 이벤트 리스너에서 roomId를 알 수있으므로 roomId 와 매핑을 위한 mapsessionIdput

  6. 재연견을 판별하여 player정보에서 sessionId를 갱신해줌

  • oldSessionId 값을 관리하기 위해 userIdLatestSession 를 생성

클라이언트는 새로고침시 바로 disconnectedsubscribe 할 것으로 가정하고 구현

📚 Reference

✅ Check List

  • 코드가 정상적으로 컴파일되나요?
  • 테스트 코드를 통과했나요?
  • merge할 브랜치의 위치를 확인했나요?
  • Label을 지정했나요?

sehee123 and others added 16 commits July 17, 2025 19:24
# Conflicts:
#	backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java
# Conflicts:
#	backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java
#	backend/src/main/java/io/f1/backend/domain/game/websocket/GameSocketController.java
#	backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java
#	backend/src/test/java/io/f1/backend/domain/game/app/RoomServiceTests.java
# Conflicts:
#	backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java
@sehee123 sehee123 self-assigned this Jul 21, 2025
@sehee123 sehee123 added the enhancement New feature or request label Jul 21, 2025
@sehee123 sehee123 linked an issue Jul 21, 2025 that may be closed by this pull request
1 task
sehee123 added 3 commits July 21, 2025 21:31
# Conflicts:
#	backend/src/main/java/io/f1/backend/domain/game/dto/RoomEventType.java
#	backend/src/main/java/io/f1/backend/domain/game/mapper/RoomMapper.java
#	backend/src/main/java/io/f1/backend/domain/game/model/Room.java
#	backend/src/main/java/io/f1/backend/domain/game/websocket/controller/GameSocketController.java
userPrincipal.getUserNickname(),
UserPrincipal.ROLE_USER);
UserPrincipal.ROLE_USER,
userPrincipal.getName());
Copy link
Collaborator

@jiwon1217 jiwon1217 Jul 21, 2025

Choose a reason for hiding this comment

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

API 명세서에 /auth/me response를 수정했습니다. 해당 PR이 merge가 되면 재연결 로직이 구현됨에 따라 명세서가 수정되었다고 말씀드리면 될 것 같습니다 !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이부분은 재연결때문에 추가한건 아니였고, 추후에 1:1 응답에서 추가될 예정이라서 그부분 구현하고나서 제가 말씀드리겠습니다!
감사합니다.. 💪

} else if (roomEventType == RoomEventType.EXIT) {
message = " 님이 퇴장하셨습니다";
} else if (roomEventType == RoomEventType.RECONNECT) {
message = " 님이 재연결 되었습니다.";
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분은 은주님 PR에서 SystemNoticeMessage enum으로 분리한 것으로 알고 있습니다. 확인부탁드립니다 ~!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 충돌 해결하면서 수정했습니다! 정리 후에 push하겠습니닷!

playerSessionMap.get(sessionId).updateState(newState);
}

public boolean isReconnectTarget(String sessionId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L4-변경제안]
isExit 메서드와 isReconnectTarget은 보수 관계인 것 같습니다.
isExit 메서드로 통합한 이후 isReconnectTarget 사용부를 !isExit()으로 대체 가능할 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

감사합니다.. 하나로 통일해서 올리겠습니다.


Message<?> message = event.getMessage();

StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(message);
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기서는 WebSocketUtils를 사용하지 않은 이유가 있을까요?

Copy link
Collaborator Author

@sehee123 sehee123 Jul 22, 2025

Choose a reason for hiding this comment

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

room 구독만을 생각하지않고 구독주소의 확장성때문에 현재 있는 고정값을 사용하지 않았습니닷 !

String sessionId = getSessionId(message);
UserPrincipal principal = getSessionUser(message);

String destination = headerAccessor.getDestination();
Copy link
Collaborator

Choose a reason for hiding this comment

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

만약, 이 로직을 위해 따로 util 을 사용하지 않았다면 room 을 알기 위해 사용하는 메서드 네임을 getRoomSubscriptionDestination 이런 식으로 해서 util로 빼는 건 어떨지 제안드려봅니다..!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

util로 빼야지~ 생각만해버렸네요 .. ㅎㅎ 감사합니다! 💪

private final Map<String, Long> sessionIdRoom = new ConcurrentHashMap<>();
private final Map<Long, String> userIdSession = new ConcurrentHashMap<>();
private final Map<Long, String> userIdLatestSession = new ConcurrentHashMap<>();
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

쓰레드풀의 개수를 1로 두면 재연결을 처리할 수 있는 하나의 스케줄러가 재연결을 하나씩 순서대로 처리하게 되어 비효율적일 것 같다는 생각이 듭니다 ! 쓰레드 풀의 개수를 늘려서 재연결을 여러 개씩 병렬적으로 처리할 수 있도록 하거나, 재연결을 처리해야하는 주체인 플레이어에게 하나씩 배정해줄 수 있을 것 같습니다 !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵! 위에 강현님 의견이랑 같이해서 고민해보겠습니다 감사합니다!


Long userId = principal.getUserId();

if (userIdLatestSession.get(userId) != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L5-참고의견]
이중 if문을 없애기 위해 null일 때는 return을 해주면서 흐름을 한 번 끊고, null이 아닐 때의 로직을 처리하는 방식도 좋을 것 같습니다.

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/sub");
registry.enableSimpleBroker("/sub", "/queue");
Copy link
Collaborator

Choose a reason for hiding this comment

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

제가 설명을 놓친 것 같은데.. 혹시 이 부분이 어떤 내용인지 알 수 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

1:1 메세지를 위한 구독채널이 추가가 되어야해서 수정된 부분입니다! 사실 이번 pr에는 포함안되어도 되는 부분이긴합니닷.

sehee123 and others added 4 commits July 22, 2025 17:23
private void removePlayer(Room room, String sessionId, Player removePlayer) {
room.removeUserId(removePlayer.getId());
room.removeSessionId(sessionId);
room.removeValidatedUserIds(removePlayer.getId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

[L5-참고의견]
얘도 아이디 하나를 지워주는 것이니 복수형보다는 removeValidatedUserId 단수형으로 수정되면 좋을 것 같습니다 !

sehee123 and others added 3 commits July 22, 2025 18:05
# Conflicts:
#	backend/src/main/java/io/f1/backend/domain/game/websocket/service/SessionService.java
Copy link
Collaborator

@jiwon1217 jiwon1217 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

Copy link
Collaborator

@silver-eunjoo silver-eunjoo left a comment

Choose a reason for hiding this comment

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

재연결 로직 .. 대단해요..! 고생하셨습니다 !! 🔥

Copy link
Collaborator

@LimKangHyun LimKangHyun left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

@sehee123 sehee123 merged commit 1f88146 into dev Jul 23, 2025
@sehee123 sehee123 deleted the feat/34 branch July 23, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 방 재연결 관리

6 participants