# How to solve the "out of ports" problem?TIME\_WAIT reusing seems not work

**URL:** <https://www.ruby-forum.com/t/how-to-solve-the-out-of-ports-problem-time-wait-reusing-seems-not-work/204285>\
**Category:** NGINX\
**Created:** [March 9, 2011, 6:51am UTC](https://www.ruby-forum.com/t/how-to-solve-the-out-of-ports-problem-time-wait-reusing-seems-not-work/204285 "2011-03-09T06:51:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 9, 2011, 6:51am UTC](https://www.ruby-forum.com/t/how-to-solve-the-out-of-ports-problem-time-wait-reusing-seems-not-work/204285/1 "2011-03-09T06:51:25Z")

</div>

I’m using nginx as reverse proxy, and find more than 30k TIME\_WAIT state  
ports in upstream server. I know my servers are “out of ports” which  
discussed here([lots of connections on TIME\_WAIT state](http://nginx.org/pipermail/nginx/2009-April/011255.html)),  
and set both nginx and upstream server to reuse TIME\_WAIT and to  
recycle more quickly.

[sysctl -p]  
……  
net.ipv4.ip\_local\_port\_range = 1024 65000  
net.ipv4.tcp\_tw\_recycle = 1  
net.ipv4.tcp\_tw\_reuse = 1

But nginx hangs and “connection timed out while connection to upstream  
server” error still can be found on nginx error log, when RPS of  
upstream is higher than 1000 within 1 minutes. When upstream is Windows,  
server will be “out of ports” in seconds.

Any ideas? A connection pool with a waiting queue? Maxim D. wrote a  
useful module to keep connection with memcached, but why can’t it  
support Web Server?

Posted at Nginx Forum:

> **[How to solve the "out of ports" problem?TIME\_WAIT reusing seems not work](https://forum.nginx.org/read.php?2,181493,181493#msg-181493)**
>
> I'm using nginx as reverse proxy, and find more than 30k TIME\_WAIT state ports in upstream server. I know my servers are "out of ports" which discussed here(http://nginx.org/pipermail/nginx/2009-April/011255.html), and set both nginx and...
