oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.09k stars 2.76k forks source link

Downloading and writing multiple files with streams hangs forever #11750

Open nshiab opened 4 months ago

nshiab commented 4 months ago

What version of Bun is running?

1.1.12+43f0913c3

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

The code below fetches and writes files one by one. It works with NodeJS, but it hangs forever with Bun.

import { createWriteStream } from "fs";
import { Readable } from "stream";
import { finished } from "stream/promises";

const urls = [
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/cities.csv",
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/dailyTemperatures.csv",
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/data.csv",
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/data.json",
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/data.tsv",
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/data.txt",
  "https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/dataArrays.json",
];

for (const url of urls) {
  const res = await fetch(url);
  const file = url.split("/").at(-1);
  const fileStream = createWriteStream(file, { flags: "w" });
  await finished(Readable.fromWeb(res.body).pipe(fileStream));
}

What is the expected behavior?

To fetch and write all files.

What do you see instead?

It fetches and writes the first two files and then hangs forever.

Additional information

Thank you for all of your work!

nektro commented 4 months ago

note to self: this reproduces with only https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/data/files/dailyTemperatures.csv. all other files work fine and the difference between them is that transfer_encoding is chunked