Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdio] Bun hangs reading from stdin pipeline at >= 16384 Bytes (16KiB) #9041

Closed
javalsai opened this issue Feb 21, 2024 · 4 comments · Fixed by #9580
Closed

[stdio] Bun hangs reading from stdin pipeline at >= 16384 Bytes (16KiB) #9041

javalsai opened this issue Feb 21, 2024 · 4 comments · Fixed by #9580
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@javalsai
Copy link

javalsai commented Feb 21, 2024

What version of Bun is running?

1.0.27+c34bbb2e3

What platform is your computer?

Linux 6.7.4-arch1-1 x86_64 unknown

What steps can reproduce the bug?

Simple passthrough from stdin to stdout:

import { Readable, pipeline, PassThrough } from 'node:stream'

pipeline(
    Readable.toWeb(process.stdin),
    new PassThrough(),
    process.stdout,
    () => { },
)

Independently of how you split it with the blocksize:
dd if=/dev/urandom bs=1 count=16383 | bun run <file>.ts > /dev/null: works without any issues
dd if=/dev/urandom bs=1 count=16384 | bun run <file>.ts > /dev/null: writes all the data to stdout, but the process hangs forever intead of stopping when stdin closes

I believe it's stdin read, as the limit is always that, even applying compression to the algorithm.

What is the expected behavior?

Process should exit normally when stdin closes, just like it does with < 16KiB data, node behaves the same.

I noticed tho, that this slight modification seems to prevent the bug:

import { Readable, pipeline, PassThrough } from 'node:stream'

pipeline(
    Bun.stdin.stream(),
    new PassThrough(),
    process.stdout,
    () => { },
)

(TS types are broken tho)

What do you see instead?

The process hangs

Additional information

A side note, isn't the callback function on pipeline supposed to be optional?
At least according to the types, excluding it doesn't cause any issue on my IDE but the code breaks:
TypeError: The "streams[stream.length - 1]" property must be of type function. Received an instance of EventEmitter
Node behaves the same, but the types shouldn't be like that imo... it's nodejs's side anyways.

@javalsai javalsai added the bug Something isn't working label Feb 21, 2024
@Jarred-Sumner
Copy link
Collaborator

This is fixed in the process PR #8456

@Electroid Electroid added the node.js Compatibility with Node.js APIs label Feb 21, 2024
@javalsai
Copy link
Author

This is fixed in the process PR #8456

It's still happening on 1.0.33, which I think that has that PR included

@jdalton
Copy link
Contributor

jdalton commented Mar 29, 2024

When fixed we should remove the 1 line-ish workaround added in: #9580.

Jarred-Sumner added a commit that referenced this issue Mar 29, 2024
* Workaround for #9041

* Fix crash with auto install

* Fixup this test

* Update 09041.test.ts

---------

Co-authored-by: Jarred Sumner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants