nodejs / nodejs/node

`fsPromise.writeFile` should catch stream's error and reject the promise.

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

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

confirmed-bug fs
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

22.16.0

Platform
All
Subsystem

No response

What steps will reproduce the bug?

Following code fails with an application crash.

import fsp from "node:fs/promises";
import { createReadStream } from "node:fs";

try {
    const s1 = createReadStream("not-existent");
    await fsp.writeFile("new-file.txt", s1);
} catch (error) {
    console.log(`Sorry file copy failed`);
}

Instead it should just say that an error has occurred and reject the promise.

How often does it reproduce? Is there a required condition?

Everytime

What is the expected behavior? Why is that the expected behavior?

The application should not crash and an error should be thrown.

What do you see instead?

Application Crashes.

Reproduction Repository

ackava/node-write-file-promise-fail

This repo contains docker container source code to reproduce error in container. On windows machine, delay causes app to crash but in container, slight delay of 1 ms causes crash.

Workaround

So far following code works correctly with slight time differences, and does not crash the app, promise is rejected correctly.

        const writable = createWriteStream(outputFilePath);
        return pipeline(inputStream, writable, { end: true });

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 với các entry point fsPromise.writeFile và createReadStream được hiển thị trong bản tái hiện, sau đó so sánh cách xử lý lỗi của chúng với workaround dùng pipeline. Sử dụng repository tái hiện được liên kết để tái hiện sự cố crash và xác minh rằng khi thiếu tệp đầu vào, promise bị reject thay vì làm ứng dụng crash.

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, nodejs
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/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.