nodejs / nodejs/node

worker: `messageerror` listeners remain during `exit`

Abierto Apto para principiantes
#65,782 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
JavaScript
Estrellas
122k
Forks
37.3k
Merge medio
4 d 2 h
PR fusionados (30 d)
283

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza en lib/internal/worker.js, alrededor de la limpieza de salida en las líneas 395-396, y compara el nombre del evento utilizado para los listeners de mensajes con el nombre del evento messageerror. Vuelve a ejecutar la reproducción del issue y confirma que ambos contadores de listeners son cero mientras se ejecuta el listener de salida.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
backend
Tipo de issue
Error
Dificultad
1/5
Tiempo estimado
Menos de una hora
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
90/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.