Buffer is not transferable in Node 21/22
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
v21.7.3, v22.11.0
Platform
Linux nweiz1 6.9.10-1rodete5-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.9.10-1rodete5 (2024-09-04) x86_64 GNU/Linux
Subsystem
worker_threads
What steps will reproduce the bug?
import {MessageChannel, Worker} from 'worker_threads';
const channel = new MessageChannel();
const buffer = Buffer.from('some text');
channel.port1.postMessage(buffer, [buffer.buffer]);
channel.port2.on('message', (e) => {
console.log(Buffer.from(e).toString());
channel.port1.close();
channel.port2.close();
});
This worked in v20 and fails in v21 and v22.
How often does it reproduce? Is there a required condition?
It always reproduces.
What is the expected behavior? Why is that the expected behavior?
The buffer should be transferred through the message channel.
What do you see instead?
node:internal/per_context/domexception:53
ErrorCaptureStackTrace(this);
^
DOMException [DataCloneError]: Cannot transfer object of unsupported type.
at new DOMException (node:internal/per_context/domexception:53:5)
at file:///.../test.mjs:5:15
at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)
Node.js v22.11.0
Additional information
I didn't see anything in the v21 or v22 changelogs about buffers becoming untransferable, and transferring it worked in v20, so I'm assuming this is unintentional. If it's intentional, I would have expected at least a deprecation message indicating that this was going to start breaking.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando la reproducción proporcionada de worker_threads MessageChannel en las versiones de Node indicadas y compara el comportamiento de transferencia. Sigue la ruta de transferencia de Buffer desde postMessage en el subsistema worker_threads; se considera terminado cuando la reproducción transfiere Buffer correctamente y existe cobertura de regresión para el comportamiento notificado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, node.js
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 48/100