fix: ResetRoom 시 BossRoom 레코드 정리
All checks were successful
Server CI/CD / lint-and-build (push) Successful in 15s
Server CI/CD / deploy (push) Successful in 57s

데디서버가 reset-room 호출 시 슬롯만 idle로 변경하고 BossRoom 레코드는
남아있어서 다음 입장 시 unique 제약 위반(Duplicate entry) 발생.
ResetRoom에서 해당 sessionName의 BossRoom 레코드도 함께 삭제.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-16 23:17:14 +09:00
parent 0ad19562a5
commit fc976dbba8
2 changed files with 11 additions and 1 deletions

View File

@@ -206,6 +206,12 @@ func (r *Repository) ResetRoomSlot(sessionName string) error {
return result.Error return result.Error
} }
// DeleteRoomBySessionName removes BossRoom records for a given session name.
// Used during ResetRoom to prevent duplicate session_name conflicts on next entry.
func (r *Repository) DeleteRoomBySessionName(sessionName string) error {
return r.db.Where("session_name = ?", sessionName).Delete(&BossRoom{}).Error
}
// ResetStaleSlots clears instanceID for slots with stale heartbeats // ResetStaleSlots clears instanceID for slots with stale heartbeats
// and resets any active raids on those slots. // and resets any active raids on those slots.
func (r *Repository) ResetStaleSlots(threshold time.Time) (int64, error) { func (r *Repository) ResetStaleSlots(threshold time.Time) (int64, error) {

View File

@@ -473,9 +473,13 @@ func (s *Service) CheckStaleSlots() {
} }
} }
// ResetRoom resets a room slot back to idle. // ResetRoom resets a room slot back to idle and cleans up any lingering BossRoom records.
// Called by the dedicated server after a raid ends and the runner is recycled. // Called by the dedicated server after a raid ends and the runner is recycled.
func (s *Service) ResetRoom(sessionName string) error { func (s *Service) ResetRoom(sessionName string) error {
// 완료/실패되지 않은 BossRoom 레코드 정리 (waiting/in_progress 상태)
if err := s.repo.DeleteRoomBySessionName(sessionName); err != nil {
log.Printf("BossRoom 레코드 정리 실패: %s: %v", sessionName, err)
}
return s.repo.ResetRoomSlot(sessionName) return s.repo.ResetRoomSlot(sessionName)
} }