wasm: Handling EPIPE from WASM seems impossible? #59099
Labels
arch-wasm
WebAssembly issues
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm the author of esbuild, a JavaScript build tool written in Go. One way to run esbuild is to use node's WebAssembly implementation with the
.wasm
file that Go generates. The esbuild library launches a child process that runs the.wasm
file and communicates with the parent process over stdin+stdout. When the parent process exits, the child process is supposed to detect that stdout is no longer writable and exit. However, I'm seeing something like this instead:Click to expand Go's verbose fatal panic log message...
What did you expect to see?
I expect
os.Stdout.Write
to returnEPIPE
if writing toos.Stdout
fails withEPIPE
.What did you see instead?
It seems like if
os.Stdout
fails withEPIPE
, Go's standard library throws an error that as far as I can tell is impossible to catch. Things I tried:I tried adding a deferred call to
recover()
, but it's never called.I tried calling
signal.Ignore(syscall.SIGPIPE)
but there is noSIGPIPE
signal when building for WASM.I dug deeper and discovered that Go's implementation for
SIGPIPE
callsthrow
which then callsfatalthrow
which I assume is impossible to catch. I'm assuming this is a bug with Go because I don't understand why it would be desirable for a Go program to unconditionally crash when encountering a normal error condition such as (in this case) the parent process exiting.I just need some way to make Go not do this, but I don't care exactly how. From my perspective I don't want to deal with
SIGPIPE
at all because it's a nuisance so ideallyos.Stdout.Write
would just returnEPIPE
. But I'm also willing to callsignal.Ignore(syscall.SIGPIPE)
beforeos.Stdout.Write
if that's the desired solution instead.The text was updated successfully, but these errors were encountered: