nuxeo / FunkLoad

Functional and load testing framework for web applications, written in Python
http://funkload.nuxeo.org/
GNU General Public License v2.0
382 stars 83 forks source link

TCP/IP Port Exhaustion on Windows #28

Open yanjost opened 13 years ago

yanjost commented 13 years ago

When using FunkLoad with a number of clients greater than 90, I get the following error :

Traceback (most recent call last):
   File "D:\funkload\lib\site-packages\funkload\FunkLoadTestCase.py", line 202, in _connect
    cert_file=self._certfile_path, method=rtype)
   File "D:\funkload\lib\site-packages\funkload\PatchWebunit.py", line 360, in WF_fetch
    h.endheaders()
   File "c:\Python27\Lib\httplib.py", line 937, in endheaders
    self._send_output(message_body)
   File "c:\Python27\Lib\httplib.py", line 797, in _send_output
    self.send(msg)
   File "c:\Python27\Lib\httplib.py", line 759, in send
    self.connect()
   File "c:\Python27\Lib\httplib.py", line 740, in connect
    self.timeout, self.source_address)
   File "c:\Python27\Lib\socket.py", line 571, in create_connection
    raise err
 error: [Errno 10048] Une seule utilisation de chaque adresse de socket (protocole/adresse réseau/port) est habituellement autorisée

This error in apparently caused by "TCP/IP port exhaustion", Windows keeps used sockets in TIME_WAIT state for 4 minutes after there have been used.

One solution is to use setsockopt on the socket to change the linger-on-close timeout value

socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, 1)

My (dirty) solution was to patch httplib.py, and after each

sock = socket.create_connection((self.host, self.port),
                                            self.timeout, self.source_address)

I added

sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, 1)

Is there a solution which would be better integrated with funkload and wouldn't need to hack into core python ?