Stop dispatching parent messages to self.onmessage in node:worker_threads workers #29215
Claude / Claude Code Review
completed
Apr 12, 2026 in 35m 25s
Code review found 1 important issue
Found 2 candidates, confirmed 2. See review comments for details.
Details
| Severity | Count |
|---|---|
| 🔴 Important | 1 |
| 🟡 Nit | 0 |
| 🟣 Pre-existing | 0 |
| Severity | File:Line | Issue |
|---|---|---|
| 🔴 Important | src/js/node/worker_threads.ts:436-438 |
parentPort.on + removeEventListener cross-API removal fails, leaking messageListenerCount |
Annotations
Check failure on line 438 in src/js/node/worker_threads.ts
claude / Claude Code Review
parentPort.on + removeEventListener cross-API removal fails, leaking messageListenerCount
When `parentPort.on('message', fn)` is called, `injectFakeEmitter` wraps `fn` into a `callback` and stores it in `trackedByListener` under `callback` as the key — not `fn`. If the user then calls `parentPort.removeEventListener('message', fn)`, `parentPortRemoveEventListener` does `trackedByListener.get(fn)`, finds nothing, and exits early without calling `releaseListener()`. This leaves `messageListenerCount` stuck above zero, keeping the capture-phase `messageForwarder` installed on `self` ind
Loading