deno_std: Uncaught BrokenPipe: Broken pipe (os error 32)

After running my ws client for 11 hours, I got this error (for the first time):

error: Uncaught BrokenPipe: Broken pipe (os error 32)   
    at unwrapResponse ($deno$/ops/dispatch_minimal.ts:63:11)
    at Object.sendAsyncMinimal ($deno$/ops/dispatch_minimal.ts:106:10)
    at async Object.write ($deno$/ops/io.ts:65:18)
    at async BufWriter.flush (https://deno.land/std@0.54.0/io/bufio.ts:479:25)
    at async writeFrame (https://deno.land/std@0.54.0/ws/mod.ts:144:3)

Any reasons as to why?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 18
  • Comments: 27 (10 by maintainers)

Most upvoted comments

@malimohub The error is that you are not catching the error… see [#659 (comment)]

Well, I have a minor objection. Because all the docs and tutorials, official or not, was pretty much using the pattern for await (req of server) directly at the top level it makes me feel like that’s how it’s intended to be used, so I expect it to not throw at all. If the intention of server is to throw, then the docs should really mention while true try catch (or whatever) instead, so that everyone isn’t surprised by the behaviour. And I agree that some error deserves to be thrown, but without proper documentation, I was under the impression that all that can go wrong should go wrong during request.respond()

So anyways maybe update the docs to reflect this? On the other hand, while true try catch at top level is really ugly lol

std/http and std/ws implementations were rewritten to leverage native HTTP bindings available in Deno (Deno.serveHttp). This error should no longer occur. I’m going to tentatively close this issue, please let me know if the problem persists.

Has anyone found a workaround for this? i.e., catching the error or restarting the server after the error occurs?

For me, Deno is currently unusable because of this, unfortunately …

This BrokenPipe: Broken pipe (os error 32) error still happens with std 0.82.0 all the time using Firefox, not so much with Chrome (although there seem to be other issues, e.g. incomplete data sometimes). It happens when I make a request in Chrome, restart Firefox and make a request there. It is strange.

Please reopen this issue!

BrokenPipe: Broken pipe (os error 32) at unwrapResponse (deno:runtime/js/10_dispatch_minimal.js:59:13) at sendAsync (deno:runtime/js/10_dispatch_minimal.js:98:12) at async write (deno:runtime/js/12_io.js:117:20) at async Object.writeAll (deno:runtime/js/13_buffer.js:223:19) at async BufWriter.flush (bufio.ts:468:7) at async writeResponse (_io.ts:288:3) at async ServerRequest.respond (server.ts:84:7)

Same problem here. Very frequently after a few hours of running (between 6 and 12 hours I guess).

Edit: Ubuntu, behind nginx, no ws - just static files and a simple api over http.

error: Uncaught (in promise) BrokenPipe: Broken pipe (os error 32)
    at unwrapResponse (deno:cli/rt/10_dispatch_minimal.js:59:13)
    at sendAsync (deno:cli/rt/10_dispatch_minimal.js:98:12)
    at async write (deno:cli/rt/12_io.js:117:20)
    at async Object.writeAll (deno:cli/rt/13_buffer.js:223:19)
    at async BufWriter.flush (bufio.ts:468:7)
    at async writeResponse (_io.ts:288:3)
    at async Server.iterateHttpRequests (server.ts:154:11)
    at async Server.acceptConnAndIterateHttpRequests (server.ts:227:5)
    at async MuxAsyncIterator.callIteratorNext (mux_async_iterator.ts:30:31)

I was also getting this error using http/serve. I now tried new unstable http api as described in Deno 1.9 blog post and couldn’t reproduce the problem (yet) 🕶.

Errors originating from HTTP server should be fixed by https://github.com/denoland/deno/pull/8365

Thanks for the suggestion!

However, this already is my configuration and Deno crashes even when using http only.

I get this error every 24h or so, after which I need to restart the process. I’m on Ubuntu, behind nginx. Server serves HTML at about 30-60 request / h. Basically the “hello world” like setup, no extra dependencies. I am on deno 1.3.x.

Please provide more reproduction. Broken pipe might happen for number of reasons, eg. the other side of connection closes it abruptly.

I get this error when I intensively fill with data of 64 kb 3000 iterations But I’m using a different language)))

let size_byte = 65535; 
let buff = (0..=size_byte).map(|_|78).collect::<Vec<u8>>();
                
addr.do_send(ClientCommand( Item::FirstBinary( Bytes::from_iter(buff.clone()))));
for i in (0..3000){
    addr.do_send(ClientCommand( Item::Continue( Bytes::from_iter(buff.clone()))));
}
addr.do_send(ClientCommand( Item::Last( Bytes::from_iter(buff.clone()))));

Error: Io(Os { code: 32, kind: BrokenPipe, message: “Broken pipe” })

@timonson The BrokenPipe error usually means trying to send data to a closed/broken connection. For example, the user interrupts loading while the browser is receiving content from the server, then the browser stops receiving, closes the connection, and causes the BrokenPipe error on the server which was sending data.

I get this error when starting a localhost webserver with for await (const req of server) { and then select a tab in Firefox from yesterday for the first time.

Probably the browser tries to use the previous connection and the server crashes because the connection is unknown.