fix: remove process signal listeners to prevent MaxListenersExceededWarning#57
Merged
YusukeHirao merged 3 commits intomainfrom Mar 13, 2026
Merged
Conversation
…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>
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.
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