Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

http.get(url, cb) hangs after 5 requests on node v0.10.32 #8443

Closed
hidekiy opened this issue Sep 24, 2014 · 1 comment
Closed

http.get(url, cb) hangs after 5 requests on node v0.10.32 #8443

hidekiy opened this issue Sep 24, 2014 · 1 comment
Labels

Comments

@hidekiy
Copy link

hidekiy commented Sep 24, 2014

I found the strange behavior when I use http.get(url, cb) simply.

I verified this on Windows 7 / 8.1, CentOS 6.5 with official binary.

node v0.11.9 looks good.

I think this condition is insufficient:
https://github.com/joyent/node/blob/v0.10.32/lib/http.js#L1694-L1698

Test code is below:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(2000);

var ix = 0;
setInterval(function () {
    http.get('http://localhost:2000/', function (r) {
        console.log({ix: ix++, status: r.statusCode});
        // the next line will resolve this problem:
        // r._dump();
    });
}, 200);

Output with NODE_DEBUG=http

HTTP: outgoing message end.
HTTP: SERVER new http connection
HTTP: write ret = true
HTTP: outgoing message end.
HTTP: AGENT incoming response!
HTTP: AGENT isHeadResponse false
{ ix: 0, status: 200 }
HTTP: outgoing message end.
HTTP: SERVER new http connection
HTTP: write ret = true
HTTP: outgoing message end.
HTTP: AGENT incoming response!
HTTP: AGENT isHeadResponse false
{ ix: 1, status: 200 }
HTTP: outgoing message end.
HTTP: SERVER new http connection
HTTP: write ret = true
HTTP: outgoing message end.
HTTP: AGENT incoming response!
HTTP: AGENT isHeadResponse false
{ ix: 2, status: 200 }
HTTP: outgoing message end.
HTTP: SERVER new http connection
HTTP: write ret = true
HTTP: outgoing message end.
HTTP: AGENT incoming response!
HTTP: AGENT isHeadResponse false
{ ix: 3, status: 200 }
HTTP: outgoing message end.
HTTP: SERVER new http connection
HTTP: write ret = true
HTTP: outgoing message end.
HTTP: AGENT incoming response!
HTTP: AGENT isHeadResponse false
{ ix: 4, status: 200 }
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
HTTP: outgoing message end.
@chrisdickinson
Copy link

You are using the default (pooled) http agent from the client, which limits the number of maximum open connections to the same server to 5. In addition, the r variable received in the callback is a ClientResponse, which is a paused readable stream. In order to free the socket back to the agent pool, you must exhaust the ClientResponse:

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(2000);

var ix = 0;
setInterval(function () {
    http.get('http://localhost:2000/', function (res) {
      // enter flowing mode
      res.resume();
      console.log({ix: ix++, status: res.statusCode});
    });
}, 200);

While this isn't a bug, it would be great to add to the http.get and http.request documentation so that future users aren't surprised by this behavior! Would you care to do the honors?

jasnell pushed a commit that referenced this issue Jun 5, 2015
You must consume the data from the response object. #8443

Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #25471
jasnell pushed a commit to nodejs/node that referenced this issue Dec 14, 2015
Refs: nodejs/node-v0.x-archive#25471
Refs: nodejs/node-v0.x-archive#8443
PR-URL: #4263
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
cjihrig pushed a commit to nodejs/node that referenced this issue Dec 15, 2015
Refs: nodejs/node-v0.x-archive#25471
Refs: nodejs/node-v0.x-archive#8443
PR-URL: #4263
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit to nodejs/node that referenced this issue Dec 30, 2015
Refs: nodejs/node-v0.x-archive#25471
Refs: nodejs/node-v0.x-archive#8443
PR-URL: #4263
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit to nodejs/node that referenced this issue Jan 19, 2016
Refs: nodejs/node-v0.x-archive#25471
Refs: nodejs/node-v0.x-archive#8443
PR-URL: #4263
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
scovetta pushed a commit to scovetta/node that referenced this issue Apr 2, 2016
Refs: nodejs/node-v0.x-archive#25471
Refs: nodejs/node-v0.x-archive#8443
PR-URL: nodejs#4263
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants