question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to handle BrokenPipe errors?

See original GitHub issue

There doesn’t seem to be a way to handle BrokenPipe errors thrown in std/http/server.ts for individual requests from oak without modifying the Application class. The error occurs if the HTTP client closes the connection prematurely.

Here is an example.

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

console.log("Starting...");

const router = new Router();
const veryLong = "foo bar baz qux ".repeat(1000000);

router.get("/demo", async ctx => {
  ctx.response.type = "text/html; charset=utf-8";
  ctx.response.body = `<h1>Hello!</h1>\n${veryLong}`;
});

const app = new Application();
app
  .use(router.routes())
  .use(router.allowedMethods())
  .listen("localhost:8080");

Save the code above as demo.ts and run the following shell commands to reproduce the error.

> deno --version
deno 0.31.0
v8 8.1.108
typescript 3.7.2
> deno --allow-net demo.ts &
> Compile file:///home/dbohdan/demo.ts
Starting...
> curl http://localhost:8080/demo & sleep 0.1; killall curl
> error: Uncaught BrokenPipe: Broken pipe (os error 32)   
► $deno$/dispatch_minimal.ts:59:11
    at DenoError ($deno$/errors.ts:20:5)
    at unwrapResponse ($deno$/dispatch_minimal.ts:59:11)
    at sendAsyncMinimal ($deno$/dispatch_minimal.ts:102:10)
fish: Job 2, “curl http://localhost:8080/demo…” terminated by signal SIGTERM (Polite quit request)
Job 1, 'deno --allow-net demo.ts &' has ended

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
kitsonkcommented, May 12, 2020

I believe that already works @hayd. I don’t have a test for it I think but should.

0reactions
haydcommented, May 12, 2020

Catching this type of error in the middleware wouldn’t work upon reflection, as the response is being sent, which is after all the middleware ran.

What about other types of error, for example some user thrown Error. Would it be possible to catch this? I was imagining something like this in the middleware:

try { await next() } catch (err) { /* render pretty error page */ }

Upon reflection, I can see it wouldn’t be as easy as that / that won’t work. But that was the usecase I was imaging…

Read more comments on GitHub >

github_iconTop Results From Across the Web

What causes the Broken Pipe Error? - Stack Overflow
The current state of a socket is determined by 'keep-alive' activity. In your case, this is possible that when you are issuing the...
Read more >
Broken Pipe Error in Python - GeeksforGeeks
A broken Pipe Error is generally an Input/Output Error, which is occurred at the Linux System level. The error has occurred during the...
Read more >
bash - How can I fix a Broken Pipe error? - Super User
Seeing "Broken pipe" in this situation is rare, but normal. When you run type rvm | head -1 , bash executes type rvm...
Read more >
How to Fix java.net.SocketException: Broken pipe in ... - Java67
These broken pipe exceptions happen when the client (browser) has closed the connection, but the server (your tag) continues to try to write...
Read more >
How to fix Broken Pipe Error in Linux - net2
This kind of error can easily be fixed with a command like “sudo apt install –f”. On rare occasions, you may have experienced...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found