oven-sh / bun

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

Bun core dumped when serve a response from spawn #6899

Open shiny opened 11 months ago

shiny commented 11 months ago

What version of Bun is running?

1.0.8+2a405f691e80725fe0b97b93afd3b8cfed13fa5f

What platform is your computer?

Linux 5.15.0-83-generic x86_64 x86_64

What steps can reproduce the bug?

Bun.serve({
    port: 8080,
    async fetch(req) {
        const proc = Bun.spawn(["echo", "hello"])
        await proc.exited
        return new Response(proc.stdout)
    },
});

Visit http://127.0.0.1:8080, then Bun would crash.

What is the expected behavior?

show stdout in web page

What do you see instead?

an error occurred Trace/breakpoint trap (core dumped)

Additional information

related https://github.com/oven-sh/bun/issues/3480#issuecomment-1793374542

cirospaciari commented 10 months ago

looks like toBlobIfPossible is not handling the stream file in all cases, in the case of subprocess.stdout the stream is readable.FIFO

https://github.com/oven-sh/bun/blob/main/src/bun.js/api/server.zig#L2697-L2698 https://github.com/oven-sh/bun/blob/main/src/bun.js/webcore/streams.zig#L115-L124