Apache sockets not closing?

I have a web application written using CherryPy, which is run locally on 127.0.0.1:4321. We use mod-rewrite and mod-proxy to have Apache act as a reverse proxy; Apache also handles our SSL encryption and may eventually be used to transfer all of our static content.

This all works just fine for small workloads. However, I recently used urllib2 to write a stress-testing script that would simulate a workload of 100 clients. After some time, each client gets a 503 error from Apache, indicating that Apache cannot connect to 127.0.0.1:4321. CherryPy is functioning properly, but my Apache error log reveals lines like the following:

[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

Googling for this error reveals that Apache has probably run out of socket file descriptors. Since I only have 100 clients running, this implies that the connections are not being closed, either between my urllib2 connection and Apache (I am definitely calling .close() on the return value of urlopen), or between Apache and CherryPy.

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

In case it matters, I'm using Python 2.5, Apache 2.2, CherryPy 3.0.3, and the server is running on Windows Server 2003.

So what's my next step to stop this problem?


Asked by: Maddie167 | Posted: 28-01-2022






Answer 1

SetEnv proxy-nokeepalive 1 would probably tell you right away if the problem is keepalive between Apache and CP. See the mod_proxy docs for more info.

Answered by: Kevin543 | Posted: 01-03-2022



Answer 2

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

There's more good information here --> http://smallvoid.com/article/winnt-tcpip-max-limit.html

Answered by: Adrian514 | Posted: 01-03-2022



Similar questions

linux - Python sockets not really closing

I have the following code in my main function: def main(): server = socket.socket(); server.bind((address, port)) server.listen(1) sock, addr = server.accept() try: while True: message = sock.recv(buffer_size) # Do some stuff... sock.send(answer) except KeyboardInterrupt: pass finally: sock.close() server.close(...


linux - Python sockets not really closing

I have the following code in my main function: def main(): server = socket.socket(); server.bind((address, port)) server.listen(1) sock, addr = server.accept() try: while True: message = sock.recv(buffer_size) # Do some stuff... sock.send(answer) except KeyboardInterrupt: pass finally: sock.close() server.close(...


Python and sockets +upnp

I have a question about python and sockets. As I understand, if you have router you must open a port before you can use it in your program. But if user can't do that... I heard something about UPnP. I don't know will it help with my problem, so I've asked you. Best regards.


PHP Sockets or Python, Perl, Bash Sockets?

I'm trying to implement a socket server that will run in most shared PHP hosting. The requirements are that the Socket server can be installed, started and stopped from PHP automatically without the user doing anything. It doesn't matter what language the socket server is written in, as long as it will run on the majority of shared hosting globally. Currently, I've written a Socket Server with PHP that imp...


sockets - Improve a IRC Client in Python

How i can make some improvement in my IRC client made in Python. The improvement is: How i can put something that the user can type the HOST, PORT, NICK, INDENT and REALNAME strings and the message? And here is the code of the program: simplebot.py import sys import socket import string HOST="irc.freenode.net" PORT=6667 NICK="MauBot" IDENT="maubot" REALNAME="MauritsBot" read...


sockets - Could not get out of python loop

I want to get out of loop when there is no data but loop seems to be stopping at recvfrom image='' while 1: data,address=self.socket.recvfrom(512) if data is None:break image=image+data count=count+1 print str(count)+' packets received...'


sockets - How to stream binary data in python

I want to stream a binary data using python. I do not have any idea how to achieve it. I did created python socket program using SOCK_DGRAM. Problem with SOCK_STREAM is that it does not work over internet as our isp dont allow tcp server socket. I want to transmit screen shots periodically to remote computer. I have an idea of maintaining a Que of binary data and have two threads write a...


sockets - help with python forking child server for doing ajax push, long polling

Alright, I only know some basic python but if I can get help with this then I am considering making it open source. What I am trying to do: - (Done) Ajax send for init content - Python server recv command "init" to send most recent content - (Done) Ajax recv content and then immediately calls back to python server - Python server recv command "wait", sets up child, and waits for command "new" from ajax - (Done) Aja...


How do you flush Python sockets?

I've written a server in Python that is meant to send data to the client in the form "Header:Message" I would like to be able to have each message sent individually so that the client will need to perform minimal work in order to read the "header" and the "message" Unfortunately, I can't figure out how to properly flush a python socket so when I have multiple sends execute in quick succession the messages ...


sockets - Python Fixed Length Packet

I am trying to build a fixed length packet in python for an ATSC PSIP generator. This is probably very simple but so far I can't seem to get it to work. I am trying to build a packet with fields similar to the following: table_id = 0xCB syntax = 0b1 reserved = 0b11 table_ext = 0xFF the end goal would be the following in binary '1100101111111111111' I hav...


sockets - Packet Queue in Python?

is there any way to queue packets to a socket in Python? I've been looking for something like the libipq library, but can't find anything equivalent. Here's what I'm trying to accomplish: Create tcp socket connection between server and client (both under my control). Try transmitting data (waiting for connection to fault -- e.g. client loses connectivity because of shutting lapt...


sockets - What can cause select to block in Python?

Here's a snippet of code I'm using in a loop: while True: print 'loop' rlist, wlist, xlist = select.select(readers, [], [], TIMEOUT) print 'selected' # do stuff At a certain point, select will block and "selected" is never getting printed. What can cause this behavior? Is it possible there's some kind of deadlock? UPDATE: I'm running on Ubuntu li...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top