Skip to content

fix: 투표 종료 푸시 알림 누락 방지#226

Merged
Junhyukkkk merged 1 commit into
developfrom
fix/push-notification-after-commit
Jun 5, 2026
Merged

fix: 투표 종료 푸시 알림 누락 방지#226
Junhyukkkk merged 1 commit into
developfrom
fix/push-notification-after-commit

Conversation

@Junhyukkkk

@Junhyukkkk Junhyukkkk commented Jun 5, 2026

Copy link
Copy Markdown
Member

📌 관련 이슈

  • closes #이슈번호

🔍 작업 내용

투표 종료 시 푸시 알림이 발송되지 않는 문제를 수정했습니다.
알림 생성 트랜잭션이 커밋되기 전에 비동기 발송 리스너가 실행돼 빈 결과를 읽고 발송이 통째로 누락되는 race condition이 원인이었습니다.

📝 변경 사항

  • PushNotificationSender: @eventlistener + @async → @TransactionalEventListener(AFTER_COMMIT) + REQUIRES_NEW 로 변경. 알림 생성 트랜잭션이 커밋된 뒤 발송하도록 해 race로 인한 발송 누락 제거
  • FcmSenderAdapter: INVALID_ARGUMENT를 만료 토큰으로 간주해 삭제하던 로직 제거 (UNREGISTERED만 삭제). 페이로드 형식 오류 시 정상 토큰까지 대량 삭제돼 영구 미발송되는 사고 방지
  • 진단성: FCM 활성(FcmSenderAdapter) / 비활성(NoOpPushSenderAdapter) 여부를 기동 로그로 식별 가능하게 추가

💬 리뷰어에게

  • @TransactionalEventListener + @async는 Spring이 동시 사용을 막아 @async를 제거했습니다. 발송은 발행 스레드(투표 종료는 notif- 비동기 풀 스레드)에서 커밋 직후 동기 실행됩니다. AdminPushService(관리자 테스트 푸시)만 요청 스레드에서 동기 발송되는데, 빈도가 낮아 허용 가능하다고 판단했습니다
  • INVALID_ARGUMENT 토큰 삭제 제거가 적절한지(UNREGISTERED만 삭제) 확인 부탁드립니다.

Summary by CodeRabbit

릴리스 노트

  • Bug Fixes

    • 푸시 알림 발송 시 토큰 처리 로직을 개선하여 불필요한 토큰 삭제를 방지했습니다.
  • Chores

    • 알림 시스템 활성화 상태를 로그로 기록하도록 개선했습니다.
    • 푸시 알림 발송의 트랜잭션 처리를 개선하여 데이터 일관성을 강화했습니다.

- PushNotificationSender를 @TransactionalEventListener(AFTER_COMMIT)로 전환해 알림 생성 트랜잭션 커밋 전 발송되던 race 제거

- FcmSenderAdapter에서 INVALID_ARGUMENT를 만료 토큰으로 오인해 정상 토큰까지 삭제하던 로직 제거 (UNREGISTERED만 삭제)

- FCM 활성/비활성 어댑터를 기동 로그로 식별 가능하게 추가
@Junhyukkkk Junhyukkkk self-assigned this Jun 5, 2026
@github-actions github-actions Bot added the bug label Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7addc2cc-70f3-4cad-bda2-f3d5abf02e2f

📥 Commits

Reviewing files that changed from the base of the PR and between 7fd4199 and 5c3b64e.

📒 Files selected for processing (3)
  • src/main/java/com/ject/vs/notification/adapter/out/fcm/FcmSenderAdapter.java
  • src/main/java/com/ject/vs/notification/adapter/out/fcm/NoOpPushSenderAdapter.java
  • src/main/java/com/ject/vs/notification/event/PushNotificationSender.java

Walkthrough

FCM 어댑터에 활성화/비활성화 상태 로깅을 추가하고, 토큰 만료 판정을 UNREGISTERED 조건으로 제한하며, 푸시 알림 이벤트 처리를 트랜잭션 커밋 이후로 변경했습니다.

Changes

FCM 어댑터 개선

Layer / File(s) Summary
FCM 어댑터 활성화 로깅
src/main/java/com/ject/vs/notification/adapter/out/fcm/FcmSenderAdapter.java, src/main/java/com/ject/vs/notification/adapter/out/fcm/NoOpPushSenderAdapter.java
@PostConstruct 메서드 logActivation()을 추가하여 어댑터 생성 시점에 FCM 활성화(또는 비활성화) 상태를 로깅합니다. FcmSenderAdapter는 "FCM enabled" 메시지, NoOpPushSenderAdapter는 WARN 레벨로 firebase.service-account-path 미설정 및 푸시 미발송 상태를 기록합니다.
토큰 만료 판정 로직 개선
src/main/java/com/ject/vs/notification/adapter/out/fcm/FcmSenderAdapter.java
collectExpiredTokens 메서드에서 삭제 대상으로 간주하는 MessagingErrorCodeUNREGISTERED만으로 제한합니다. 기존의 INVALID_ARGUMENT 포함 처리를 제거하여, 일시적 오류로 인한 토큰 손실을 방지하면서도 경고 로그는 유지합니다.

알림 이벤트 트랜잭션 개선

Layer / File(s) Summary
이벤트 처리 트랜잭션 타이밍 변경
src/main/java/com/ject/vs/notification/event/PushNotificationSender.java
이벤트 리스너 어노테이션을 @EventListener + @async("notificationExecutor") + @Transactional``에서 @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true) + @Transactional`(propagation = Propagation.REQUIRES_NEW)`로 변경합니다. 이를 통해 푸시 발송 로직이 부모 트랜잭션 커밋 완료 후 새로운 트랜잭션에서 실행되어, 커밋 이전 별도 스레드 실행으로 인한 데이터 조회 누락 race condition을 회피합니다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • tlarbals824
  • KII1ua

Poem

🐰 토큰 관리는 신중하게,
트랜잭션은 순서대로,
로그는 명확하게!
경쟁 조건을 피하고
안정적인 발송을 위해 🚀

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/push-notification-after-commit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Junhyukkkk Junhyukkkk merged commit 9da43e0 into develop Jun 5, 2026
2 of 3 checks passed
@github-actions github-actions Bot deleted the fix/push-notification-after-commit branch June 5, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant