# Keepalive\_timeout not working?

**URL:** <https://www.ruby-forum.com/t/keepalive-timeout-not-working/236294>\
**Category:** NGINX\
**Created:** [August 22, 2013, 8:03pm UTC](https://www.ruby-forum.com/t/keepalive-timeout-not-working/236294 "2013-08-22T20:03:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 22, 2013, 8:03pm UTC](https://www.ruby-forum.com/t/keepalive-timeout-not-working/236294/1 "2013-08-22T20:03:32Z")

</div>

keepalives seem to be working, but the timeout limit I’m setting isn’t  
honored it seems… Someone let me know if I’ve done something wrong or  
am missing something.

I have nginx installed on Ubuntu from the stable repository at  
[nginx.org](http://nginx.org). Nothing has been added, nothing removed.

# ================================== nginx version: nginx/1.4.2 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client\_temp –http-proxy-temp-path=/var/cache/nginx/proxy\_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi\_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi\_temp –http-scgi-temp-path=/var/cache/nginx/scgi\_temp --user=nginx –group=nginx --with-http\_ssl\_module --with-http\_realip\_module –with-http\_addition\_module --with-http\_sub\_module –with-http\_dav\_module --with-http\_flv\_module --with-http\_mp4\_module –with-http\_gunzip\_module --with-http\_gzip\_static\_module –with-http\_random\_index\_module --with-http\_secure\_link\_module –with-http\_stub\_status\_module --with-mail --with-mail\_ssl\_module –with-file-aio --with-http\_spdy\_module --with-cc-opt=‘-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wp,-D\_FORTIFY\_SOURCE=2’ –with-ld-opt=‘-Wl,-Bsymbolic-functions -Wl,-z,relro’ --with-ipv6

In my http block, I have the following.

keepalive\_timeout 3s;

That is the only place the string ‘keepalive’ exists.

# ================================= root@web:/etc# grep -r “keepali” . grep: ./blkid.tab: No such file or directory Binary file ./alternatives/rsh matches Binary file ./alternatives/rlogin matches ./nginx/nginx.conf: keepalive\_timeout 3s;

Yet, when I take a look at netstat -tc, I have waay too many http  
connections in a TIME\_WAIT state and they seemingly stay there forever.  
Obviously it’s not forever, but it’s not closing in 3 seconds.

## Thanks.

Sajan P.  
Owner, Noppix LLC

o: (563) 726-0371  
c: (563) 508-3184

---

<div class="post-metadata">

**Author:** ![Sajan\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba9def/32.png) [@Sajan\_P](https://www.ruby-forum.com/u/Sajan_P)\
**Post date:** [August 22, 2013, 8:35pm UTC](https://www.ruby-forum.com/t/keepalive-timeout-not-working/236294/2 "2013-08-22T20:35:05Z")

</div>

Hello!

On Thu, Aug 22, 2013 at 01:03:01PM -0500, Sajan P. wrote:

> keepalives seem to be working, but the timeout limit I’m setting  
> isn’t honored it seems… Someone let me know if I’ve done something  
> wrong or am missing something.

[…]

> Yet, when I take a look at netstat -tc, I have waay too many http  
> connections in a TIME\_WAIT state and they seemingly stay there  
> forever. Obviously it’s not forever, but it’s not closing in 3  
> seconds.

TIME\_WAIT is a TCP state, and any socket is expected to be in  
this state on a side which does an active close for 2 \* MSL  
seconds after a connection is closed.

Reducing keepalive\_timeout isn’t expected to reduce number of  
sockets in a TIME\_WAIT state. On the contrary, it may cause more  
connections to be established and then closed, resulting in more  
sockets in TIME\_WAIT state.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)
