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

Uncaught BrokenPipe: Broken pipe (os error 32) #659

Closed
ITS-NIGHTOWL opened this issue Jun 16, 2020 · 27 comments
Closed

Uncaught BrokenPipe: Broken pipe (os error 32) #659

ITS-NIGHTOWL opened this issue Jun 16, 2020 · 27 comments
Labels
bug Something isn't working

Comments

@ITS-NIGHTOWL
Copy link

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/[email protected]/io/bufio.ts:479:25)
    at async writeFrame (https://deno.land/[email protected]/ws/mod.ts:144:3)

Any reasons as to why?

@wongjiahau
Copy link
Contributor

I'm also getting this error, but for different reasons

@bartlomieju
Copy link
Member

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

@colorhook
Copy link

colorhook commented Aug 6, 2020

WebSocket demo reload web page and deno server exit

And I cannot catch the exception

async function dispatch(msg: string): Promise<void> {
  for (const client of clients.values()) {
    try {
      await client.send(msg)
    } catch (err) {}
  }
}

Exception Stack Message

Uncaught BrokenPipe: Broken pipe (os error 32)   
    at unwrapResponse (rt/10_dispatch_minimal.js:52:13)
    at sendAsync (rt/10_dispatch_minimal.js:95:12)
    at async write (rt/12_io.js:117:20)
    at async Object.writeAll (rt/13_buffer.js:223:19)
    at async BufWriter.flush (bufio.ts:467:7)
    at async writeFrame (mod.ts:141:3)

deno version

deno 1.2.0
v8 8.5.216
typescript 3.9.2

@Caesar2011
Copy link

Caesar2011 commented Sep 27, 2020

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.

@lmiller1990
Copy link

lmiller1990 commented Sep 30, 2020

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.

@rvdende
Copy link

rvdende commented Oct 29, 2020

Running into this as well.. about 12 hours after starting the service. Might be that the client changed ip addresses and that confused deno or something like that? Also Deno error message doesn't tell me where in my code the issue originated from.

error: Uncaught 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 BufWriter.write (bufio.ts:499:29)
    at async writeResponse (_io.ts:273:15)
    at async ServerRequest.respond (server.ts:84:7)
    at async Response.end (response.ts:218:5)

@leogreu
Copy link

leogreu commented Nov 13, 2020

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)

@leogreu
Copy link

leogreu commented Nov 16, 2020

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 ...

@rvdende
Copy link

rvdende commented Nov 16, 2020

Closest I found to a workaround is to switch to http and run a nginx reverse proxy with the certificate/key infront of deno

@leogreu
Copy link

leogreu commented Nov 16, 2020

Thanks for the suggestion!

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

@bartlomieju
Copy link
Member

Errors originating from HTTP server should be fixed by denoland/deno#8365

@timonson
Copy link
Contributor

timonson commented Dec 29, 2020

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)

@bartlomieju bartlomieju transferred this issue from denoland/deno Feb 1, 2021
@lideming
Copy link
Contributor

@timonson

at async ServerRequest.respond (server.ts:84:7)

Do you use other library or call ServerRequest.respond directly? The caller have to catch and handle the error.

@timonson
Copy link
Contributor

Thanks for coming back to this issue @lideming !

Although I still don't know what exactly causes this error, it looks like I made a mistake in my error handling function.
I caught the error on req.respond({status: 200}) correctly, but what I forgot is adding a catch statement to req.respond({status: 500}) inside my error handler function.

@lideming
Copy link
Contributor

@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.

@nuts-n-bits
Copy link

nuts-n-bits commented Feb 26, 2021

For me this error tends to happen when I saturate the TCP connection, maybe some connection gets dropped by the os for whatever reason and now you're writing to a broken pipe. What makes it troubling is that this is uncatchable within the for await loop, from limited testing, it seems the way to catch it is this:

while(true) {
    try {
        for await (const request of server) {
            // serve the request
        }
    } 
    catch(e) {
         // handel error 
    }
}

The reason of which I'm sure can be made sense of by folks who understand how async iterators work better than I do, but I'm still confused by this lol.

Edit: So I know now that the error occurs at the point where the for await calls the .next() of the server iterator, and #761 fixes this where the error is a NotConnected.

@OverGlass
Copy link

Same problem for me. Every 6 -12 hours of running.
On Ubuntu, behind nginx. - Deno 1.8.0

  • static files server
  • api over HTTP

How can I help for debugging this ? This is in production and I really want to dig into this.

@malimohub
Copy link

Is there a fix coming out for this? Deno is pretty unusable at this point

@lucacasonato
Copy link
Member

@malimohub The error is that you are not catching the error... see #659 (comment). It is totally expected for this error to happen (connections sometimes close unexpectedly). It might be more obvious what is happening if instead of using for await, you called const req = await server.next() in an infinite loop manually.

@nuts-n-bits
Copy link

@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

@hiral-kotadiya
Copy link

0|app      |     at async Collection.findOne (https://raw.githubusercontent.com/manyuanrong/deno_mongo/refactor/src/collection/collection.ts:43:12)
0|app      | 2021-03-26T06:15:07.234Z [10] BrokenPipe: Broken pipe (os error 32) 
0|app      |     at unwrapResponse (deno:runtime/js/10_dispatch_minimal.js:60:13)
0|app      |     at sendAsync (deno:runtime/js/10_dispatch_minimal.js:99:12)
0|app      |     at async write (deno:runtime/js/12_io.js:118:20)
0|app      |     at async Object.writeAll (deno:runtime/js/13_buffer.js:224:19)
0|app      |     at async WireProtocol.command (https://raw.githubusercontent.com/manyuanrong/deno_mongo/refactor/src/protocol/protocol.ts:55:7)

In my case, broken pipe error generated from deno_mongo.

@zigomir
Copy link

zigomir commented Apr 15, 2021

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) 🕶.

@MrOggy85
Copy link

I also switch to the new api, but got the same error as mentioned previously in this issue.
However, I was not using await with respondWith. When I added await I successfully caught the error and the execution could continue.

await respondWith(
  new Response(body, {
    headers,
    status: 200,
  }),
);

I made the same mistake with the previous api, by not prefixing request.respond with await.

@bartlomieju
Copy link
Member

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.

@ralyodio
Copy link

does this impact oak?

I'm runngin puppeteer and if I do 5 instances at a time it crashes.

@bartlomieju
Copy link
Member

oak doesn't use std/http anymore in the latest version so it shouldn't be affected.

@Jekahome
Copy link

Jekahome commented Dec 16, 2021

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" })

inverted-capital pushed a commit to dreamcatcher-tech/napps that referenced this issue Oct 24, 2024
Currently, when you add your own license to modified files, it will
complain.

This changes the regex so that it can be multiline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests