-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Too many sockets of Ubuntu with 'CLOSE_WAIT' #2440
Comments
Anybody can help? Because the proxy server would close my socket when I requested too fast so it is necessary to close the socket connection gracefully to prevent ports number increasing on and on.Now I got thousands of ports with CLOSE_WAIT status. |
I find the code from request.js below, and my error code is ECONNRESET. I'm not sure below code would close the request socket?
|
/cc @mscdex |
It doesn't sound like this is related to #2438. @mike442144 Does downgrading to |
@mscdex I've downgraded to 2.69.0, there also have thousands of CLOSE_WAIT sockets. tunnel-agent/index.js
request.js
The only questions we should care about are: Thanks a lot. It's very nice of you to help. |
ECONNRESET is never an http thing, it means the other end abruptly/forcefully closed the TCP connection for whatever reason. I do not know why artificial ECONNRESET errors are being created though, that seems wrong to me. Since I'm not familiar with the proxying part of the code base, I don't know what to suggest except use an http/https.Agent that has a cap on the maximum number of sockets (the default global Agent instances have no limits in modern versions of node) and/or use keep-alive in said Agent as much as possible? |
@mscdex according to the code in
Thanks very much. |
Anybody can help? |
I had a similar issue. I have this X server(Tomcat/Java) that had some legacy APIs deployed on it. I needed to bypass all those API through my node server. For that purpose, I am using request-promise-native which is based upon 'request'. Out of nowhere, X server started taking too long for response. I thought its the npm package thats messing it up. But later I realized the X server was taking to some other(db) and not closing the connection(sockets) properly. Because of which it had hundreds of ports active. I restarted that server and it started working fine. I was able to figure it out by running 'netstat' on the server and checking foreign address. TL;DR It was the X server that was messing up things, not this package itself. Hope it helps. |
@harshitgupta Thanks a lot, I'm doing this to confirm request handle the socket close event correctly, because I use the request module as a client to connect to a proxy server, and received a lot of ECONNRESET message, I have to know whether this module close the socket or not. If not, why and how? Server is ready to close the socket As the above,our program do not send FIN packet to server. |
I have captured the packets between proxy server and my process and rename the src IP as local -> sdr [SYN] Obviously, my process didn't send FIN to notify the server. Anybody who know how to close the underlying socket manually ? |
Updated: below solution doesn't work!!!! It seems I cannot get 'end' event on underlying socket if connect is established and statusCode is not 200, but received 'end' event when onError. Why? will it be a bug of I can fix the problem now, but I would like to confirm some code in I have tested the tunnel-agent for a few days, and finally I found number of CLOSE_WAIT was equal to number of error which statusCode was not equal to 200 in
Socket document about But, I'm not sure why should the socket remove all listeners? |
@simov @mscdex @mikeal
Why ???? Why does it remove all listeners? Obviously I cannot receive |
I'm not that familiar with tunnel-agent. The original author of that code is maintaining it here: https://github.com/koichik/node-tunnel I diffed the two code bases and I spotted only minor visual differences, and in fact our test suite here in request is passing with either module. So I'm for switching to the original You can modify -, tunnel = require('tunnel-agent')
+, tunnel = require('tunnel') Good job on this issue 👍 |
@simov I've read the source code of tunnel, it still has this problem, I'm going to open a PR. and I suggest you to switch to original tunnel after the PR merged. I'll tell you. |
@mike442144 hi, i have the same environment with you. can you show the whole code? thank you. i mean i wanna see how to use the error callback when upgrade to your code version |
@kazaff please refer to https://github.com/bda-research/tunnel-agent/tree/callback, it's easy to fix, but deep enough. Before merged to master and republished, you can use my repo as a dependency. |
@mike442144 thanks a lot~ and, i wonder that if need change my business code to adapt your repo. i read the source code by self. and base on your solution, i confuse at Request error event. now i add some code , its look like: var socketHold = null; // add new code
Request
.get({/*some config*/}, function(err, response){/*my original code*/})
.on('error', function(error){
// add new code
console.error('Request on error');
console.error(error.stack);
if(socketHold){
socketHold.emit('free');
}
}).on('socket', function(socket){
socketHold = socket;
}); do i need to do like that? or just do nothing only change the dependency to your repo? need your help, thank very much. |
@kazaff What you should do is using
That's it. |
@mike442144 ok, cool. i'll be try it. |
I notice @mikeal have new version published of tunnel-agent, which break my project. Because version only between 0.4.1 to 0.5.0 will use my own repo. |
link to PR? |
@mikeal How are you going to deal with the issue? Just ask, since I haven't seen any update :) |
+1 I'm running on Ubuntu and this issue can easily cause node to balloon to thousands of sockets. Also, there was a PR that applied options.timeout to the CONNECT request, that would also be useful. |
Is anyone looking at this? I'm also effected by it |
@mattdonnelly Use my repo as your dependency,git://github.com/bda-research/tunnel-agent.git#timeout and add npm-shrinkwrap.json as I mentioned above. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hey, @mikeal , Do you have chance to merge my request to tunnel-agent? It has big impact to long live program with proxy. Currently we have to write npm-shrinkwrap to revert back the version. You've see so many people have the same problem and my code fix it well, mentioned in this issue. I want to know how can you merge it, and if you're not in charge of this repo so who else should I contact ? Or is there any other steps I missed. Also pls pay attention to this comment @simov @mscdex , Hope to make it recently, thank you so much. :) |
I had the same issue, and I updated my the tunnel-agent/index.js with @mike442144 's code from his PR and it fixed the issue. It has been almost 4 years since this bug was exposed and had a potential fix, I just wonder is there any official update from @mikeal on this issue? |
Please reopen this issue, even npm-shrinkwrap is included in the project, didnt't work now. |
request version: 2.76.x
system: Ubuntu
I'm using request via proxy with TLS, and after a long time I have thousands of socket ports in
CLOSE_WAIT
status, I google it , and find maybe the remote server force close my socket would lead to this, but what I want is to detect the event and close the socket gracefully or the ports will be exhausted and the process would never work.Dose this related to #2438 ?
Thanks.
The text was updated successfully, but these errors were encountered: