Skip to content

Fix/#350 자동로그인 오류 해결#355

Merged
5 commits merged intodevelopfrom
fix/#350-자동로그인-오류-해결
Feb 17, 2026

Hidden character warning

The head ref may contain hidden characters: "fix/#350-\uc790\ub3d9\ub85c\uadf8\uc778-\uc624\ub958-\ud574\uacb0"
Merged

Fix/#350 자동로그인 오류 해결#355
5 commits merged intodevelopfrom
fix/#350-자동로그인-오류-해결

Conversation

@y-eonee
Copy link
Collaborator

@y-eonee y-eonee commented Feb 12, 2026

🔗 연결된 이슈

📄 작업 내용

  • 자동로그인 이슈 해결했습니다 !!!!!!!!!!!!!

IMG_3570

💻 주요 코드 설명

문제 원인 분석

image 문제 상황을 다시 재연해보니, 이틀 뒤, 30분 뒤.. 에 다시 들어갔을 때부터 자동로그인이 풀린다는 문제를 짚을 수 있었습니다 현재 액세스토큰 유효시간은 10분, 리프레시토큰은 2주입니다 !! 그래서 저는 액세스토큰이 만료되었을 때 reissue가 잘 되는 것 같지 않다고 판단하고 로그를 찍어보았습니다 image

로그가 너무 길어서 ;; 요약으로 대체합니다
여튼 요약하자면 autologin 함수에서 토큰 재발급을 잘 받았는데, 거의 동시에 호출되는 notification-tokens api에는 만료된 액세스토큰이 들어가게 되어 reissue를 호출하게 됩니다. 그러면 이미 새 토큰을 받았는데 만료된 토큰으로 reissue를 호출하게 되면 또 401에러가 나게 됩니다.. 이때 clearKeychain이 실행되게 되면서 앞으로 자동로그인을 할 수 없게 됩니다 (키체인에 토큰이 있는지 확인하기 때문에)

동시성의 문제라고 판단하고 actor로 TokenService를 리팩토링했습니다 어렵더라구여 .. .. .

코드 설명

func reissue() async throws {
   // 이미 진행중인 토큰 태스크가 있다면 
    if let task = tokenTask {
        return try await task.value // 그 태스크 그냥 실행한다 
    }
    // 없으면 새로운 컨텍스트를 만든다 
    let task = Task {
        try await fetchAuthReissue()
    }

    // 토큰태스크에 새로만든 태스크 할당   
    tokenTask = task
    // 리이슈 끝나면 nil로 바꿔줌 
    defer { tokenTask = nil }
    
    // 결과를 리턴 
    return try await task.value
    }

아직 근데 너무 어렵네요 actor가 ..

📚 참고자료

https://dawning-record.tistory.com/132
https://sujinnaljin.medium.com/swift-actor-%EB%BF%8C%EC%8B%9C%EA%B8%B0-249aee2b732d
https://yunie-studylog.tistory.com/81

@y-eonee y-eonee self-assigned this Feb 12, 2026
@y-eonee y-eonee added 나연🐹 fix 버그나 오류 해결 labels Feb 12, 2026
Copy link
Collaborator

@dev-domo dev-domo left a comment

Choose a reason for hiding this comment

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

잘 봤습니다! reissue 메서드에서 Task 상태를 점검하는 로직 좋은 것 같아요!

그런데 fetchAuthReissue 메서드에서 Alamofire가 제공하는 responseDecodable을 활용하잖아요? 찾아보니까 responseDecodable은 아래처럼 구현되어있어요.

Image

responseDecodable이 디폴트로 메인 큐를 활용한다는 뜻인 것 같은데, 그렇다면 이 로직이 액터 외부에서 실행되는 건 아닐지 궁금합니다. 한 번 확인을 부탁드릴게요!

더불어 현재 develop 브랜치 작업에서 reissue 메서드를 살펴보면 아래와 같은 노란색 에러가 있어요.

Image

제가 강의를 통해 듣기로는 클로저에 캡처된 값(여기서는 self)은 Sendable해야 하는 것으로 알고 있는데 아마 현재는 클로저에 캡처된 self가 Sendable하지 않아 저런 노란색 에러가 있는 것 같아요. 이것도 확인 부탁드리겠습니다!

Copy link
Collaborator

@juri123123 juri123123 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 코멘트 확인 한 번만 부탁드려요 ~

Comment on lines 49 to 55
AF.request(
AuthAPI.reissue(header: header).requestURL,
method: AuthAPI.reissue(header: header).method,
parameters: AuthAPI.reissue(header: header).bodyParameters,
encoding: AuthAPI.reissue(header: header).parameterEncoding,
headers: AuthAPI.reissue(header: header).headers.value
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분 API.reissue()로 인해서 같은 객체가 계속 재생성되는 것 같은데 확인 부탁드려요 !

NotificationCenter.default.post(name: .navigateLoginViewController, object: nil)

Task {
await self.debugTokenReissueSuccess(data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 친구가 하는 역할이 단순 디버그가 아니라면 함수명을 더 직관적으로 바꿔주면 좋을 것 같아요!


case .failure(let error):
Task {
await self.debugTokenReissueFailure()
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 친구 또한 ~

Comment on lines +93 to +95
DispatchQueue.main.async {
NotificationCenter.default.post(name: .navigateLoginViewController, object: nil)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 친구만 concurrency를 사용하지 않은 이유가 궁금해요 !

)
.validate()
.responseDecodable(of: BaseResponse<TokenReissueResponseDTO>.self) { [weak self] response in
guard let self else { return }
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기서 continuation resume이 안되고 있어요 ! 누수가 발생할 가능성이 있어보입니다

@y-eonee y-eonee closed this pull request by merging all changes into develop in a81569c Feb 17, 2026
@y-eonee y-eonee deleted the fix/#350-자동로그인-오류-해결 branch February 17, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 버그나 오류 해결 나연🐹

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants