feat(database): PostgreSQL 런타임 연결 타임아웃 보호 추가 - #73
Open
krestar wants to merge 1 commit into
Open
Conversation
- PostgreSQL Runtime Hikari Connection에 statement_timeout과 lock_timeout을 적용한다. - 타임아웃 설정값의 범위, 밀리초 정밀도 및 상호 관계를 시작 단계에서 검증한다. - 충돌하거나 초기화 보장을 훼손하는 DataSource 설정을 거부한다. - PostgreSQL 예외를 statement timeout, lock timeout 및 ambiguous 상태로 보수적으로 분류한다. - 확인된 타임아웃을 안전한 503 응답과 저카디널리티 metric으로 기록한다. - SQL, 진단 메시지 및 raw URI가 노출되지 않도록 로그를 제한한다. - 설정 예시와 운영·롤백 가이드를 문서화한다. - 단위, Context 및 실제 PostgreSQL 통합 테스트를 추가한다. - Flyway와 기존 Outbox 동작은 변경하지 않는다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
왜 필요한가요?
PostgreSQL Runtime Connection에 SQL 실행 시간과 lock 대기 시간을 제한하는 안전선이 없어,
장시간 쿼리나 lock 경합이 Hikari Connection Pool 전체 장애로 확산될 수 있었습니다.
Runtime Connection이 생성될 때 PostgreSQL Session timeout을 적용하고,
확인된 timeout을 안전한 HTTP 응답과 metric으로 분류하기 위한 변경입니다.
무엇이 바뀌나요?
API·도메인·DB 변경:
statement_timeout과lock_timeout을 Session 범위로 초기화합니다.lock < statement관계를 시작 단계에서 검증합니다.503 SERVICE_TEMPORARILY_UNAVAILABLE로 응답합니다.500 INTERNAL_SERVER_ERROR를 유지합니다.권한·Workflow 변경:
AI·외부 연동 변경:
문서·배포 변경:
DB_STATEMENT_TIMEOUT과DB_LOCK_TIMEOUT환경변수 예시를 추가합니다.lc_messages가 영어가 아닐 때 confirmed timeout이 과소 분류될 수 있는 한계를 명시합니다.어떻게 검증했나요?
./gradlew clean test./gradlew build/health와 Swagger UI 확인PostgreSQL 17 Docker 테스트 DB에서 다음 명령을 실행했습니다.
결과:
추가로 다음 내용을 단위·Context·PostgreSQL 통합 테스트로 검증했습니다.
보안·개인정보
company_id범위를 검사합니다.request_id로 추적됩니다.request_id, HTTP method, 안전한 route pattern과 저카디널리티 분류값만 기록합니다.Proposed로 작성했습니다.Confirmed 및 ambiguous timeout 로그에는 SQL, bind parameter, PostgreSQL diagnostic 원문, credential, raw URI와 stack trace를 기록하지 않습니다.
API·DB·운영 영향
Idempotency-Key가 보장될 때만 재시도해야 합니다.Retry-After는 제공하지 않습니다..env.example에 적었습니다.DB_STATEMENT_TIMEOUTDB_LOCK_TIMEOUTcurrent_setting을 확인합니다.화면 또는 응답 예시
확인된 PostgreSQL Runtime timeout 응답은 기존 공통 오류 형식을 사용합니다.
{ "timestamp": "2026-07-31T12:00:00Z", "status": 503, "code": "SERVICE_TEMPORARILY_UNAVAILABLE", "message": "일시적으로 요청을 처리할 수 없습니다. 잠시 후 다시 시도해 주세요.", "path": "/api/tasks", "request_id": "example-request-id", "field_errors": [] }응답과 애플리케이션 로그에는 SQL, PostgreSQL diagnostic 원문, credential 또는 개인정보가 포함되지 않습니다.
리뷰할 부분
hywznn: 전체 구조와 운영 안정성 측면에서 놓친 위험이나 기존 기능에 미치는 영향이 없는지 확인 부탁드립니다.chaeliki: 오류 응답과 트랜잭션 처리 흐름이 자연스러운지 확인 부탁드립니다.