Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[fix] 예약/결제 동시성 취약점 수정 (레이스 컨디션 및 오버부킹) #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
[fix] 예약/결제 동시성 취약점 수정 (레이스 컨디션 및 오버부킹) #158
Changes from 4 commits
3ced6656e3c14ad89fd22bab83c38ab24a99117e44ebaed6b8a28e523442430aa1cbedd01060b568d29eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uq_booking_table_slot유니크 제약 조건은 오버부킹을 방지하는 강력한 수단이지만, 현재 구현상 심각한 부작용이 있습니다. 예약이 취소(CANCELED)되어도BookingTable레코드가 삭제되지 않고 유지되기 때문에, 취소된 예약이 점유했던 동일한 시간대에 다른 사용자가 예약을 시도하면 DB 제약 조건 위반으로 인해 재예약이 불가능해집니다. 이를 해결하려면 예약 취소 시 연관된BookingTable데이터를 삭제(또는 Soft Delete 처리 후 유니크 인덱스에서 제외)하는 로직이 반드시 추가되어야 합니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
기존 테이블에
NOT NULL컬럼 추가 시 데이터 백필 마이그레이션 필요booking_date/booking_time컬럼은nullable = false로 추가되지만, 기존booking_table행에는 해당 값이 없습니다. 마이그레이션 스크립트 없이 적용하면NOT NULL제약 위반으로 마이그레이션이 실패합니다.권장 마이그레이션 순서:
NULLABLE로 추가booking의booking_date/booking_time으로 백필BookingTable행을 삭제(유니크 제약 충돌 방지,Booking.cancel()수정과 함께)NOT NULL제약 추가또한
BookingCommandServiceImpl.createBooking의bookingRepository.flush()(Line 130)에서 유니크 제약 위반 시DataIntegrityViolationException이 발생하므로, 글로벌 예외 핸들러에서 이를 명시적으로 "이미 예약된 슬롯" 오류로 처리해야 합니다.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findByIdWithLock에 락 타임아웃이 설정되지 않아 무한 블로킹 위험@Lock(PESSIMISTIC_WRITE)는SELECT ... FOR UPDATE를 발행하지만, 타임아웃 힌트가 없으면 락을 보유한 트랜잭션이 느릴 때(예:cancelBooking/cancelBookingByOwner에서 Toss 외부 API 호출 중) 대기 트랜잭션이 무한정 블로킹되어 DB 커넥션 풀이 고갈될 수 있습니다.🛡️ 제안 수정
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
락/REQUIRES_NEW 적용은 잘 되어 있으며, 매직 문자열 상수화 및 ID 전용 프로젝션 쿼리 권장
전체 구조(락 재조회 + 독립 트랜잭션 + PENDING 재검증)는 적절합니다. 두 가지 사소한 개선 의견입니다.
"결제 시간 초과로 인한 자동 취소"는 매직 문자열입니다. 향후 다른 자동 취소 사유가 추가되거나 다국어화 시 분기점이 되도록 상수로 추출하는 편이 안전합니다. (코드 품질 가이드: 매직 넘버/하드코딩 값 점검)findExpiredPendingIds가 만료 후보Booking엔티티 전체를 로드한 뒤 ID만 추출합니다. 만료 건수가 많아질 경우 메모리/연관 lazy 프록시 비용이 누적되므로, 리포지토리에@Query("select b.id from Booking b where b.status = ?1 and b.createdAt < ?2")형태의 ID 전용 쿼리를 추가하는 편이 효율적입니다. (성능 가이드: 불필요한 DB 쿼리/Stream 효율성)♻️ 제안 수정 — 상수 추출 및 메소드 레퍼런스
위 코딩 가이드라인의 “3. 성능 및 효율성: 불필요한 DB 쿼리 호출…”과 “2. 코드 품질 & 가독성: 매직 넘버, 하드코딩된 값이 존재하는지 점검”에 따른 의견입니다.
🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.