nodejs / nodejs/node

Buffer is not transferable in Node 21/22

Ouverte
#55,593 19 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

buffer web-standards
Langage dominant
JavaScript
Étoiles
122k
Forks
37.3k
Merge moyen
4 j 2 h
PR mergées (30 j)
283

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter la reproduction fournie de worker_threads MessageChannel sur les versions de Node indiquées et comparez le comportement du transfert. Suivez le chemin de transfert de Buffer depuis postMessage dans le sous-système worker_threads ; la tâche est terminée lorsque la reproduction transfère Buffer avec succès et qu’une couverture de régression du comportement signalé existe.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, node.js
Domaine
backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.