oven-sh / bun

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

Bun hangs when running `linguist-js` #13425

Open karimbeyrouti opened 2 months ago

karimbeyrouti commented 2 months ago

What version of Bun is running?

1.1.20 and 1.1.24

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Running the linguist-js package intermittently hangs, with the task never completing.

1) We made a test repo, to help debug this issue. Essentially bun hangs when running the following script:

import linguist from 'linguist-js';
await linguist('./node_modules');

2) BUG: it hangs intermittently, and never finishes - during our debugging sessions we identified LinguistJS was hanging here when calling fs.createReadStream

3) We also tried the same with latest release of NodeJS, which consistently worked as expected

What is the expected behavior?

Task should complete without hanging

What do you see instead?

console is hung / task never finishes

Additional information

No response

vitch commented 2 months ago

We dug into this further and updated the test repo. It turns out there are two places in linguist-js which both need to be changed to bypass the bug - vitch/bun-linguist-hang#2 patches linguist-js and changes the file access to sync (from streams) and the bug no longer reproduces.

Note that this is a workaround rather than a solution - obviously the original script should work as well in bun as it does in node. But hopefully it helps to show how to easily reproduce the problem...