nodejs / nodejs/node

Buffer is not transferable in Node 21/22

Đang mở
#55,593 19 bình luận 2 reaction 0 người được giao Xem trên GitHub

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

buffer web-standards
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

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.

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 bằng cách chạy bản tái hiện worker_threads MessageChannel được cung cấp trên các phiên bản Node đã liệt kê và so sánh hành vi truyền. Theo dõi đường đi truyền Buffer từ postMessage trong subsystem worker_threads; được xem là hoàn tất khi bản tái hiện truyền Buffer thành công, cùng với kiểm thử hồi quy cho hành vi đã được báo cáo.

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, node.js
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
48/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.