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

Unexpected http agent keepAlive behaviour #16148

Closed
joachimvh opened this issue Oct 11, 2017 · 2 comments
Closed

Unexpected http agent keepAlive behaviour #16148

joachimvh opened this issue Oct 11, 2017 · 2 comments
Labels
http Issues or PRs related to the http subsystem. question Issues that look for answers.

Comments

@joachimvh
Copy link

  • Version: v8.4.0
  • Platform: Windows 7 (64 bit)
  • Subsystem: http

When using an http agent with keepAlive: true and not completely draining the request response,
the process sometimes terminates immediately and sometimes keeps waiting until the connection gets closed.

var http = require('http');
var url = require('url');

var settings = url.parse(URL);
settings.agent = new http.Agent({ keepAlive: true });

var request = http.request(settings, function (response) {
    console.log('response');
});
request.end();

In the code above, when URL gets replaced with http://google.com,
the process will remain running for several minutes and then terminate.
The same occurs with URL http://fragments.dbpedia.org/en

When doing the same with http://www.google.be (which is what google.com redirects me to,
so will probably provide different results for everyone) the process terminates immediately,
most of the time. Sometimes the result is the same as in the first scenario.
URL http://fragments.dbpedia.org/2016-04/en provides the same result

A third scenario is with http://httpstat.us/200, where after a few minutes the process
terminates with a ECONNRESET error.

In all 3 scenarios the 'response' string gets printed immediately.
Since this might be a timing issue those URLs might not return the same results depending on who runs it.

When checking with wireshark, in the first scenario the communication gets terminated
with a FIN message sent by the server.

In the second scenario a RST message gets sent by the client to the server,
and in the third scenario a RST message gets sent by the server to the client.

Now, scenario 1 and 3 I understand since the connection is still running so the agent keeps the socket open.
But why does the socket immediately get closed by the client in scenario 2?
Is this expected behaviour or is this a timing issue?

@mscdex mscdex added the http Issues or PRs related to the http subsystem. label Oct 11, 2017
@tim-soft
Copy link

Possibly related?
#15082

@apapirovski
Copy link
Member

@joachimvh I realize this is super late but I'm pretty sure this is because it responds with transfer-encoding: chunked, right? I don't think those connections are reusable.

@apapirovski apapirovski added the question Issues that look for answers. label Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

4 participants