Bug 36770

Summary: KeepAliveTimeout is ignored in all but the first VirtualHost
Product: Apache httpd-2 Reporter: J <jaeschke>
Component: DocumentationAssignee: HTTP Server Documentation List <docs>
Status: RESOLVED FIXED    
Severity: minor CC: jeremyk, takashi.asfbugzilla
Priority: P4 Keywords: PatchAvailable
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: add a note

Description J 2005-09-22 13:52:48 UTC
It's not possible to assign different values of KeepAliveTimeout
to different <VirtualHost>s. In every VirtualHost (in which KeepAlive is set to
On) the value of KeepAliveTimeout from the first VirtualHost is used.
Comment 1 Jeremy Kitchen 2007-08-22 16:24:25 UTC
I'm currently experiencing this bug as well.  I do have a little more
information about it, however.

It appears that the limit is not per server overall, it's per IP address.

Say we have something like this:
<VirtualHost 127.0.1.2:80>
ServerName virt1.example.com
KeepAliveTimeout 20
</VirtualHost>

<VirtualHost 127.1.2.3:80>
ServerName virt2.example.com
KeepAliveTimeout 14
</VirtualHost>

<VirtualHost 127.0.1.2:80>
ServerName virt3.example.com
KeepAliveTimeout 3
</VirtualHost>

<VirtualHost 127.1.2.3:80>
ServerName virt4.example.com
KeepAliveTimeout 12
</VirtualHost>

Then the keepalivetimeouts per domain will be the following:
virt1.example.com: 20
virt2.example.com: 14
virt3.example.com: 20
virt4.example.com: 14

Additionally, if we remove the KeepAliveTimeout setting from the
virt1.example.com virtualdomains, then both virt1.example.com and
virt3.example.com will revert to the default of 15 (or the global setting
specified outside of a virtualhost)

Coincidentally, you can still toggle keepalives on and off per domain,
regardless of load order.  If we change our config to look something like this:
<VirtualHost 127.0.1.2:80>
ServerName virt1.example.com
KeepAliveTimeout 20
</VirtualHost>

<VirtualHost 127.1.2.3:80>
ServerName virt2.example.com
KeepAliveTimeout 14
KeepAlive Off
</VirtualHost>

<VirtualHost 127.0.1.2:80>
ServerName virt3.example.com
KeepAliveTimeout 3
</VirtualHost>

<VirtualHost 127.1.2.3:80>
ServerName virt4.example.com
KeepAliveTimeout 12
</VirtualHost>

then virt2.example.com will not allow keepalives, and virt4.example.com will
have a 14 second keepalive timeout.

I can provide a full config file if need be.  I'm using apache 2.0.54 with the
following modules loaded (not in any particular order):
mod_autoindex
mod_auth
mod_auth_digest
mod_auth_mysql
libphp4
mod_access
mod_actions
mod_alias
mod_cgi
mod_deflate
mod_dir
mod_env
mod_expires
mod_headers
mod_include
mod_log_config
mod_logio
mod_mime
mod_negotiation
mod_rewrite
mod_ssl
mod_suexec
mod_fastcgi
mod_security
mod_setenvif
mod_encoding
mod_dav
mod_dav_fs
mod_cband
mod_dav_svn
mod_authz_svn
mod_limitipconn

Some of those modules might be in-house, although I don't think so.  If one
isn't recognized, let me know and I will find out where it came from.

If you need any additional information, I can provide anything required, just
say the words :)
Comment 2 Ruediger Pluem 2007-08-23 11:34:21 UTC
This works as designed. KeepaliveTimeout is a connection property (you can sent
requests to different name based virtual hosts over the same TCP/IP connection)
thus is cannot be set differently in name based virtual hosts. As you have seen
it is perfectly possible to adjust it individually for IP/Port based virtual
hosts. In the case of name based virtual hosts it is the usual behaviour to use
the setting of the first name based virtual host (the default host) for such
properties.
I admit that this is not clearly expressed in the documentation. So I leave this
report open as a documentation bug.
Comment 3 Jeremy Kitchen 2007-08-23 11:53:42 UTC
it's strange though, that you can *disable* keepalives on a per virtualhost
basis, but not change the timeout?
Comment 4 Ruediger Pluem 2007-08-23 12:34:38 UTC
(In reply to comment #3)
> it's strange though, that you can *disable* keepalives on a per virtualhost
> basis, but not change the timeout?

This is a partial valid point, but

If a request goes to a name based host that has set keepalive off the connection
can be shutdown by the server and this seems to be the right thing to do in this
situation.
On the other hand if a request goes to a name based virtual host and the next
request on this connection goes to a different name based virtual host. What is
the correct keepalive timeout to use?
You could find arguments for both options:
1. It should be the one of the host that just processed the request.
2. It should be the one of the host that processes the next request.
Comment 5 Jeremy Kitchen 2007-08-23 13:24:49 UTC
(In reply to comment #4)
> This is a partial valid point, but
> 
> If a request goes to a name based host that has set keepalive off the connection
> can be shutdown by the server and this seems to be the right thing to do in this
> situation.

Agreed.

> On the other hand if a request goes to a name based virtual host and the next
> request on this connection goes to a different name based virtual host. What is
> the correct keepalive timeout to use?
> You could find arguments for both options:
> 1. It should be the one of the host that just processed the request.
> 2. It should be the one of the host that processes the next request.

we can't possibly know what host is going to process the next request though,
since we haven't even gotten the request.  I would say it makes the most sense
to use the keepalivetimeout setting for the virtualhost that processed the most
recent request.  Not to mention that such a scenario is probably pretty highly
unlikely.
Comment 6 Takashi Sato 2008-01-25 16:30:07 UTC
Created attachment 21432 [details]
add a note
Comment 7 Takashi Sato 2008-05-06 10:58:46 UTC
committed as r653856 for trunk
Comment 8 Takashi Sato 2008-05-12 08:52:01 UTC
An improved patch was committed in r655438.
backported to 2.2 as r655477.
2.0 as r655483.