🧪 fix(logging): unref StructuredLogger interval — jest teardown leak 제거#38
Conversation
…leak StructuredLogger's processing setInterval (started at module load via the `logger` singleton -> constructor -> startProcessing) was never cleared in tests, keeping jest from exiting -> 'A worker process has failed to exit gracefully' on every test:ci run (6 open handles via --detectOpenHandles, all the same StructuredLogger setInterval). Potential CI flakiness. Fix: call .unref() on the interval (guarded by typeof for browser safety) so the timer no longer keeps the Node process alive. Production behavior unchanged — the 100ms queue processing still runs while the app is live; child loggers go through the same startProcessing so they're covered too. Verify: jest --detectOpenHandles reports 0 handles (was 6), test:ci exits 0 with 389/389 passing and no force-exit warning, tsc/lint clean. PDCA: asca-jest-teardown-leak (do).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
More reviews will be available in 51 minutes and 54 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Note
|
| Layer / File(s) | Summary |
|---|---|
setInterval unref() 수정 및 플랜 문서 lib/logging/structured-logger.ts, docs/01-plan/features/asca-jest-teardown-leak.plan.md |
startProcessing() 내부 setInterval 반환값에 typeof unref === 'function' 가드 후 processingInterval.unref()를 호출해 프로세스 종료를 차단하지 않도록 조정. 플랜 문서에는 --detectOpenHandles로 확인한 근본 원인, 성공 기준, 브라우저 호환 리스크 완화 방안이 포함됨. |
도구 메타데이터 및 커밋 메시지 갱신 .bkit-memory.json, .commit_message.txt |
activeFeature를 asca-jest-teardown-leak으로, phase를 do로 변경하고 parallelFeatures 실행 기록을 추가. 커밋 메시지를 이번 수정 내용으로 교체. |
Estimated code review effort
🎯 1 (Trivial) | ⏱️ ~3 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | PR 제목이 주요 변경 사항을 명확하게 요약하고 있으며, StructuredLogger의 interval unref 처리를 통한 Jest teardown leak 제거라는 핵심 의도를 효과적으로 전달합니다. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
fix/jest-teardown-leak
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
문제
npm run test:ci매 실행마다 "A worker process has failed to exit gracefully ... improper teardown" 경고.jest --detectOpenHandles결과 6개 open handle 전부 동일 원인 —StructuredLogger의setInterval. CI flaky 잠재 요인.근본 원인
lib/logging/structured-logger.ts:435export const logger = StructuredLogger.getInstance()가 모듈 import 시점에 인스턴스화 → constructor →startProcessing()(397)setInterval(processQueue, 100ms).logger를 (transitive) import하는 테스트들에서 이 타이머가 안 꺼져 jest가 종료를 못 함. child logger도 동일.수정 (기능 코드 1파일, 프로덕션 무변경)
startProcessing()의 interval에.unref()(브라우저 안전typeof가드) 추가 → 타이머가 Node 프로세스 종료를 막지 않게 함. 실행 중 100ms 큐 처리는 그대로 동작.startProcessing단일 경로라 singleton+child logger 일괄 해결.검증
jest --detectOpenHandles: "Jest has detected ... open handles" 사라짐 (6 → 0)test:ci: exit 0 · 389/389 pass · force-exit 경고 0tsc --noEmit0 · lint 0 errors (10 max-lines warning 불변)Test plan
checkjob green (e2e는 pre-existing Clerk 키 인프라 블로커 — 본 PR 무관)PDCA: asca-jest-teardown-leak (Plan+Do 완료). 머지 후 report→archive.
Summary by CodeRabbit
릴리스 노트
Bug Fixes
Documentation