Skip to content

fix: remove process signal listeners to prevent MaxListenersExceededWarning#57

Merged
YusukeHirao merged 3 commits intomainfrom
fix/process-signal-listener-leak
Mar 13, 2026
Merged

fix: remove process signal listeners to prevent MaxListenersExceededWarning#57
YusukeHirao merged 3 commits intomainfrom
fix/process-signal-listener-leak

Conversation

@YusukeHirao
Copy link
Copy Markdown
Member

@YusukeHirao YusukeHirao commented Mar 13, 2026

Summary

  • process.on(signal) で登録したシグナルハンドラが removeListener されず蓄積し、テスト時に MaxListenersExceededWarning が発生していた
  • crawl.ts: eventAssignments() 完了後に finally ブロックでリスナーを解除
  • archive.ts: getArchive() がクリーンアップ関数 removeSignalHandlers を返す ArchiveHandle を返すように変更
  • report.ts: getArchive() 以降のロジック全体を try/finally でラップし、例外時もリスナー解除 + archive.close() を保証

テスト追加

  • archive.spec.ts: 新規作成。リスナー登録・解除・蓄積防止を検証
  • report.spec.ts: 正常時・例外時の removeSignalHandlers / archive.close 呼び出しを検証
  • crawl.spec.ts: 複数回 startCrawl 呼び出し後のリスナー蓄積防止、エラー時のリスナー解除を検証

Test plan

  • yarn test で全 106 ファイル・711 テスト通過
  • yarn test 2>&1 | grep MaxListeners で警告が出力されないことを確認
  • yarn build 成功

🤖 Generated with Claude Code

YusukeHirao and others added 3 commits March 13, 2026 20:45
…arning

Signal handlers registered via process.on() were never cleaned up,
causing listener accumulation across repeated test runs.

- crawl.ts: remove signal listeners in finally block after eventAssignments completes
- archive.ts: return removeSignalHandlers cleanup function from getArchive
- report.ts: call removeSignalHandlers before archive.close()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- report.ts: wrap post-getArchive logic in try/finally to guarantee
  removeSignalHandlers + archive.close on any exception path
- archive.spec.ts: new unit tests for getArchive signal listener
  registration and cleanup
- report.spec.ts: verify removeSignalHandlers and archive.close are
  called on both success and error paths
- crawl.spec.ts: verify signal listeners do not accumulate across
  repeated startCrawl calls and are cleaned up on error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- crawl.ts: document automatic signal handler removal in finally block
- ARCHITECTURE.md: reflect getArchive returning ArchiveHandle with
  removeSignalHandlers, and the cleanup step in the report sequence

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@YusukeHirao YusukeHirao merged commit b0fbf45 into main Mar 13, 2026
3 checks passed
@YusukeHirao YusukeHirao deleted the fix/process-signal-listener-leak branch March 13, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant