-
Notifications
You must be signed in to change notification settings - Fork 7.3k
big bug for http-agent keep alive?? #1958
Comments
This looks like it behaves like it should: The connection is kept alive. What did you expect it to do ? |
because we use agent in js client, so just only one socket/connection is needed. |
Can you post the server code? |
It is entirely possible that those extra connections are for automatic resources such as the favicon. Browsers make these calls without being invoked. |
Oh, my bad, you're using a HTTP utility to test it. |
the server is a cluster writen by my own : when a worker received a socket handle posted by master process , |
@bnoordhuis
|
You don't set a |
when I write code like below in server: res.writeHead(200 ,{"content-type" : "text/html"});
res.end("hello,world"); nodejs will automatically add 'transfer-encoding': 'chunked' I inspect the response headers in client : { 'content-type': 'text/html',
connection: 'keep-alive',
'transfer-encoding': 'chunked' } so I think there is another hidden bug caused this problem |
Right, that's true. The bug is in your test though: |
Besides that ,could you please give some tips on how to make http-keep-alive requests, I think the current implement of Agent has the pitfall ,maybe it should expose a property like :
just as
if user sets it to a number less than 0 ,it will be persistent, for common http request ,we use global.agent ,which is a special instance of Agent then we are compatible with the old api |
No. Keeping idle connections around just because you can is bad Internet neighbourship. If you want to do that, either implement your own http.Agent class or keep the request queue filled. |
I have added some words... for common http request ,we use global.agent ,which is a special instance of Agent global.agent.maxSockets = 5
global.maxKeepAliveTime = 0 //close immediately when we finish a request then we are compatible with the old api for Nodejs is mostly used as a middle-ware , |
If anyone needs a "real" keep-alive implementation, I shared mine: (not yet perfect... but worked for my problem, and you can improve :) @bnoordhuis That is untrue. You can equally be a bad internet neighbor with the current implementation by spamming TCP SYN / FIN (if you send requests one-by-one to an endpoint -- you need the response to construct the next request for example -- this might be a more common use case than you think). |
I don't know about your browser but my FF 13 install doesn't keep the connection open if there's nothing to do. Re: keep-alive, we may add a one tick respite, i.e. don't close the connection until the next tick of the event loop. That gives people time to queue a new request in the 'end' listener of the current request. |
I have just done a quick test with FF 13 and Chrome 19 on Mac, opened an url, and checked the TCP connections with netstat. It seems to me with both browsers the connections stay in ESTABLISHED state for around a minute, by default. |
We just ran into problems with the current implementation. In our case, our node.js processes do a http query from Amazon DynamoDB Database. Our servers had tens of thousands of TCP connection in TIME_WAIT state, so they're actually preventing new connections in the entire server. The http requests are so fast that even with out server doing about 200 requests per second, there's practically no time when the requests will be queued with the http client so that keep-alive would be used. |
I have a basic keep-alive agent implementation, but it may be useful to start out to solve your case: https://gist.github.com/atimb/2963672 |
The "bad neighbourship" argument is relative. Leaving unnecessary connections open is wasteful and closing them is probably a good default, but constantly closing and opening connections (quickly consuming available sockets on the remote server by leaving them in a TIME_WAIT state) can also be "bad neighbourship." I think this should be configurable. FWIW, I'm aware that there is a related discussion of what to do with request-less HTTP errors resulting from disconnects, but I don't see why that prevents optional socket reuse. |
Maintenance release Notable Changes: * v8: Fixed an out-of-band write in utf8 decoder. This is an important security update as it can be used to cause a denial of service attack. * openssl: - Upgrade to 1.0.2b and 1.0.2c, introduces DHE man-in-the-middle protection (Logjam) and fixes malformed ECParameters causing infinite loop (CVE-2015-1788). See the security advisory for full details. (Shigeki Ohtsu) nodejs#1950 nodejs#1958 * build: - Added support for compiling with Microsoft Visual C++ 2015 - Started building and distributing headers-only tarballs along with binaries
I found it doesn't work ,
well ,maybe my test way isn't correct , but please just check keep-alive feature again
I think the test file : test-http-keep-alive.js isn't so valuable.
my test code :
client:
the server is writen by me ,and when it got a connection it will print a line
the js test result is 10 lines:
get a connection
get a connection
get a connection
get a connection
get a connection
get a connection
get a connection
get a connection
get a connection
get a connection
I think it should print only one line ,since we use keep-alive and only one socket is used!!!!!!
so I check it with siege (keep-alive mode)
the result is one line :
get a connection
why??
The text was updated successfully, but these errors were encountered: