nodejs / nodejs/node

Unhandled rejection event in web streams when stream error is piped

Đang mở
#50,707 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

web streams
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

21.1.0

Platform

Linux kunigunde 6.5.9-arch2-1 #1 SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:52:20 +0000 x86_64 GNU/Linux

Subsystem

streams/web

What steps will reproduce the bug?

Run the following code:

import { ReadableStream } from "stream/web";

process.on('unhandledRejection', (err) => {
	console.log(`Unhandled rejection: ${err.message}`);
});

const stream1 = new ReadableStream({
	start(controller) {
		controller.error(new Error('Test'));
	},
});

const stream2 = new TransformStream();

stream1.pipeTo(stream2.writable);

try {
	await stream2.readable.getReader().read();
} catch (err) {
	console.log(`Caught error: ${err.message}`);
}
How often does it reproduce? Is there a required condition?

With the given code example, it happens every time.

It does not happen in the following situations:

  • Reading from stream1 directly rather than piping it to stream2
  • Reading from stream2 but not catching the error but letting the app crash instead
What is the expected behavior? Why is that the expected behavior?

No unhandledRejection event should be triggered, since the exception is actually handled.

What do you see instead?

An unhandledRejection event is triggered. The output of the sample script is:

Caught error: Test
Unhandled rejection: Test
Workaround

I’m not sure if this has any unintended side effects, but catching the rejection by the promise returned by pipeTo() seems to solve the problem:

stream1.pipeTo(stream2.writable).catch(() => {});

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 được cung cấp và kiểm tra đường dẫn streams/web pipeTo, tập trung vào cách rejection của nó được lan truyền khi readable đích được tiêu thụ. Hoàn tất khi lỗi stream đã bắt được không còn kích hoạt sự kiện unhandledRejection, trong khi hành vi hiện có đối với các lỗi đã bắt được vẫn được giữ nguyên.

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ó
3/5
Thời gian dự kiến
1-2 ngày
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
68/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.