nodejs / nodejs/node

worker: `messageerror` listeners remain during `exit`

Đang mở Phù hợp với người mới
#65,782 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.4k
Merge trung bình
4 ngày 3 giờ
Pull request đã merge (30 ngày)
272

Mô tả

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:

https://github.com/nodejs/node/blob/7177c14789a7376866dfe6c04f5cd4da489cfbe6/lib/internal/worker.js#L395-L396

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong lib/internal/worker.js, tại phần dọn dẹp khi thoát ở các dòng 395-396, và so sánh tên sự kiện được dùng cho các listener của message với tên sự kiện messageerror. Chạy lại bản tái hiện từ issue và xác nhận rằng cả hai số lượng listener đều bằng 0 trong khi listener thoát đang chạy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
90/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.