Is it possible to handle BrokenPipe errors?
See original GitHub issueThere 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:
- Created 4 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I believe that already works @hayd. I don’t have a test for it I think but should.
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: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…