Apache sockets not closing?

I have a web application written using CherryPy that runs locally on 127.0.0.1:4321 . We use mod-rewrite and mod-proxy so that Apache acts as a reverse proxy; Apache also handles our SSL encryption and can ultimately be used to migrate all of our static content.

All this is great for small workloads. However, I recently used urllib2 to write a stress testing script that would simulate a workload of 100 clients. After a while, each client receives a 503 error from Apache, indicating that Apache cannot connect to 127.0.0.1:4321 . CherryPy is working fine, but my Apache error log shows lines like:

[Thu Oct 02 12:55:44 2008] [error] (OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted. : proxy: HTTP: attempt to connect to 127.0.0.1:4321 (*) failed

Google for this error shows that Apache probably ran out of socket file descriptors. Since I only have 100 clients, this means the connections are not closing, either between my urllib2 connection and Apache (I definitely call .close() on the returned urlopen value), or between Apache and CherryPy.

I confirmed that my urllib2 request sends an HTTP Connection: close header, although Apache is configured with KeepAlive On , if that matters.

In case it matters, I use Python 2.5, Apache 2.2, CherryPy 3.0.3, and the server runs on Windows Server 2003.

So what is my next step to stop this problem?

+4
source share
2 answers

SetEnv proxy-nokeepalive 1 will probably tell you right away if the problem is with Apache and CP. See mod_proxy docs for more information.

+5
source

You can run the netstat command and see if you have a bunch of sockets in TIME_WAIT state. Depending on your MaxUserPort, you may be very limited in the number of available ports. In addition, TcpTimedWaitDelay is usually set to 240 seconds, so any sockets that are used cannot be reused for four minutes.

Here's more good info -> http://smallvoid.com/article/winnt-tcpip-max-limit.html

+5
source

Source: https://habr.com/ru/post/1277404/


All Articles