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

std/http: close connection on .respond() error #3475

Merged

Conversation

kevinkassimo
Copy link
Contributor

@kevinkassimo kevinkassimo commented Dec 9, 2019

Previously we did not handle automatic connection closing on .respond() error. This leaves the supposedly dead connection not closed (CLOSE_WAIT) (since req.done is never resolved due to error), resulting in errors like Too many files open. (which might be the cause of #3463 (comment))

A simple demonstration of what this patch fixes is with the following:

import { serve } from 'https://deno.land/std/http/server.ts';
const body = new TextEncoder().encode("Hello World\n");
const s = serve({ port: 8000 });

console.log("Listening on port 8000");

setInterval(() => {
  console.log(Object.keys(Deno.resources()).length);
}, 10000);

for await (const req of s) {
  req.respond({ body }).catch(() => {});
}

If you fire a few autocannon -c 100 -d 5 -p 10 https://localhost:8000 to this, you'll notice that Object.keys(Deno.resources()).length keeps growing. (likely due to autocannon closing conn on its side thus making .respond() fail (especially under pipelining))

With this patch, Object.keys(Deno.resources()).length should eventually return to a fixed amount.

@kevinkassimo
Copy link
Contributor Author

Seems windows behaves slightly differently here?

const server = serve(":8124");
const serverRid = server.listener["rid"];
let connRid = -1;
for await (const req of server) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be waiting for the next req (on my machine)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that should be the reason. I wonder why the second req.respond() does not fail on windows...

@kevinkassimo
Copy link
Contributor Author

kevinkassimo commented Dec 11, 2019

I'm thinking about probably skipping the added test for now on Windows, since the original behavior is indeed incorrect, and this change does not break other existing tests... (I don't have a Windows platform for me to experiment on...)

@ry
Copy link
Member

ry commented Dec 11, 2019

Kevin - yes that sounds good .. please leave a Todo comment explaining the situation

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks Kevin!

@ry ry merged commit c3c69af into denoland:master Dec 12, 2019
bartlomieju pushed a commit to bartlomieju/deno that referenced this pull request Dec 28, 2019
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants