classification
Title: FD leak in SocketServer
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, draghuram, giampaolo.rodola, luke-jr, mcjeff
Priority: high Keywords:

Created on 2007-11-12 12:27 by luke-jr, last changed 2011-06-12 22:25 by terry.reedy.

Messages (6)
msg57396 - (view) Author: Luke-Jr (luke-jr) Date: 2007-11-12 12:27
SocketServer.ThreadingUnixStreamServer leaks file descriptors when a 
request handler throws an exception.
msg57471 - (view) Author: Raghuram Devarakonda (draghuram) Date: 2007-11-13 20:45
Please provide a small test code that manifests the problem. It is
always the best way to get quick response.
msg104814 - (view) Author: Jeff McNeil (mcjeff) Date: 2010-05-03 04:17
I was toying with adding Unix Socket support for one of our internal tools and I thought I ran into a leak in my own code. Searched the bug tracker and found this.

I tried to reproduce, but wasn't able to. Though, if you look at the ThreadingMixIn class, you'll see this:

self.handle_error(request, client_address)
self.close_request(request)

An exception in handle_error, most likely from a subclass, would cause close_request to never fire. Though, the socket.accept'd channel would probably be shut down implicitly when leaving _handle_request_nonblock.
msg116786 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-09-18 14:37
This will go nowhere unless a patch is provided that contains code, doc and unit test changes.
msg116788 - (view) Author: Jeff McNeil (mcjeff) Date: 2010-09-18 14:51
I'll see if I can get it to reproduce and put a patch together.
msg130788 - (view) Author: Jeff McNeil (mcjeff) Date: 2011-03-14 04:50
I entirely forgot I had signed up to look, my apologies. 

I'm going through this w/ what's lying on Mercurial's tip, I can't reproduce it at all. I can raise exceptions of various flavors from within the handle method of a StreamRequestHandler and there are no leaking file descriptors.  

The only thing worthy of discusion, IMO, is the fact that raising an exception in a handle_error method of a subclass of BaseServer *does* cause the the self.shutdown_request to not run.  

Unless I'm mistaken, that does then leave the cleanup of that open socket to GC (but, at that point, anyone overriding handle_error method should know that). Does it make sense to run shutdown_request, even if handle_error throws an Exception?  

If anyone thinks that's worthwhile, I can do that.
History
Date User Action Args
2011-06-12 22:25:17terry.reedysetversions: + Python 3.3, - Python 3.1
2011-03-14 04:50:24mcjeffsetnosy: draghuram, giampaolo.rodola, luke-jr, mcjeff, BreamoreBoy
messages: + msg130788
2010-09-18 14:51:49mcjeffsetmessages: + msg116788
2010-09-18 14:37:10BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
nosy: + BreamoreBoy

messages: + msg116786

type: behavior
stage: test needed
2010-05-03 04:17:24mcjeffsetnosy: + mcjeff
messages: + msg104814
2008-06-04 02:14:23giampaolo.rodolasetnosy: + giampaolo.rodola
2008-01-20 19:54:28christian.heimessetpriority: high
versions: + Python 2.6, - Python 2.4
2007-11-13 20:45:42draghuramsetnosy: + draghuram
messages: + msg57471
2007-11-12 12:27:34luke-jrcreate