[New-bugs-announce] [issue3066] FD leak in urllib2
Bohdan Vlasyuk
report at bugs.python.org
Mon Jun 9 13:03:09 CEST 2008
New submission from Bohdan Vlasyuk <bohdan at google.com>:
In urllib2.AbstractHTTPHandler.do_open, the following like creates a
circular link:
r.recv = r.read
[r.read is a bound method, so it contains a reference to 'r'. Therefore,
r now refers to itself.]
If the GC is disabled or doesn't run often, this creates a FD leak.
How to reproduce:
import gc
import urllib2
u = urllib2.urlopen("http://google.com")
s = [ u.fp._sock.fp._sock ]
u.close()
del u
print gc.get_referrers(s[0])
[<socket._fileobject object at 0xf7d42c34>, [<socket object, fd=4,
family=2, type=1, protocol=6>]]
I would expect that only one reference to the socket would exist (the
"s" list itself).
I can reproduce with 2.4; the problems seems to still exist in SVN HEAD.
----------
components: Library (Lib)
messages: 67860
nosy: bohdan
severity: normal
status: open
title: FD leak in urllib2
type: resource usage
versions: Python 2.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3066>
_______________________________________
More information about the New-bugs-announce
mailing list