worker: `messageerror` listeners remain during `exit`
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
Version
v24.14.1
The typo is also present in the v26.8.1 source and
in the current main branch.
Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem
worker_threads
What steps will reproduce the bug?
Run the following without any third-party dependencies:
const { Worker } = require('node:worker_threads');
const worker = new Worker('', { eval: true });
const listener = () => {};
worker.on('message', listener);
worker.on('messageerror', listener);
worker.on('exit', () => {
console.log({
message: worker.listenerCount('message'),
messageerror: worker.listenerCount('messageerror'),
});
});
How often does it reproduce? Is there a required condition?
It reproduces every time on v24.14.1 and on the current main branch at
7177c14789a7376866dfe6c04f5cd4da489cfbe6. It occurs both when a worker exits
normally and when it is stopped with worker.terminate().
What is the expected behavior? Why is that the expected behavior?
Both messaging listener counts should be zero while the exit listener is
running:
{ message: 0, messageerror: 0 }
The worker exit cleanup explicitly removes the message listeners before
emitting exit and appears intended to do the same for messageerror.
What do you see instead?
The message listener is removed, but the messageerror listener is still
present:
{ message: 0, messageerror: 1 }
Additional information
The targeted cleanup currently calls
removeAllListeners('messageerrors'), but the event name is messageerror:
The typo was introduced in commit 5968c5423530aeaa10c02eae3e8423c6514cdd1a:
https://github.com/nodejs/node/commit/5968c5423530aeaa10c02eae3e8423c6514cdd1a
There is a later generic removeAllListeners() call after the exit event is
emitted, so this report does not claim a persistent listener leak. The observed
problem is that the targeted pre-exit cleanup does not remove messageerror
listeners as intended.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib/internal/worker.js の 395-396 行目付近にある終了時のクリーンアップから始め、メッセージリスナーに使用されているイベント名と messageerror イベント名を比較してください。issue の再現手順をもう一度実行し、終了リスナーの実行中に両方のリスナー数が 0 であることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 90/100