[Patches] [ python-Patches-1093468 ] socket leak in SocketServer

SourceForge.net noreply at sourceforge.net
Thu Feb 24 21:14:50 CET 2005


Patches item #1093468, was opened at 2004-12-30 21:57
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1093468&group_id=5470

Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Shannon -jj Behrens (jjinux)
Assigned to: Nobody/Anonymous (nobody)
Summary: socket leak in SocketServer

Initial Comment:
Found in Python 2.3.4 but still present in 2.5.
FreeBSD 4.9

Summary:
Fixed a socket leak in
SocketServer.StreamRequestHandler that happens during
certain exceptions.

Longer version:
SocketServer.StreamRequestHandler.setup sets up
self.rfile and self.wfile.  The parent class,
SocketServer.BaseRequestHandler.__init__ does not call
self.finish() if there is an exception thrown in
self.handle().  Hence, such an exception leads to a
leaked socket, because
SocketServer.StreamRequestHandler.finish never gets
called.  This is a one line patch that fixes that.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2005-02-24 21:14

Message:
Logged In: YES 
user_id=21627

jjinux, I find it hard to believe that the sockets don't get
closed. Normally, with an exception, local variables survive
in the traceback. Therefore, SocketServer.py sets
sys.exc_traceback to None.

It still might be that the SocketServer is part of a cyclic
object, in which case the socket won't be closed until the
GC actually runs. However, I believe the intention is that
the SocketServer normally isn't cyclic. 

Can you provide a test case showing the problem?

----------------------------------------------------------------------

Comment By: Shannon -jj Behrens (jjinux)
Date: 2005-01-18 20:59

Message:
Logged In: YES 
user_id=30164

Unfortunately, that is not the case according to my testing.
 I can get it to leak sockets and never reclaim them. :-/

----------------------------------------------------------------------

Comment By: Irmen de Jong (irmen)
Date: 2005-01-16 16:55

Message:
Logged In: YES 
user_id=129426

Looks harmless enough but aren't the sockets just garbage
collected once the request has been handled?
Because the request handler class is instantiated for each
request and so it will be removed once done, taking the
sockets with it, right?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1093468&group_id=5470


More information about the Patches mailing list