mirror of
https://github.com/python/cpython.git
synced 2025-08-17 15:21:26 +00:00
Issue #10883: Fix socket leaks in urllib.request.
* ftpwrapper now uses reference counting to ensure that the underlying socket is closed when the ftpwrapper object is no longer in use * ftplib.FTP.ntransfercmd() now closes the socket if an error occurs Initial patch by Victor Stinner.
This commit is contained in:
parent
578617ad45
commit
b42c53e442
6 changed files with 65 additions and 31 deletions
|
@ -1399,7 +1399,8 @@ class FTPHandler(BaseHandler):
|
|||
raise URLError, ('ftp error: %s' % msg), sys.exc_info()[2]
|
||||
|
||||
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
|
||||
fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
|
||||
fw = ftpwrapper(user, passwd, host, port, dirs, timeout,
|
||||
persistent=False)
|
||||
## fw.ftp.set_debuglevel(1)
|
||||
return fw
|
||||
|
||||
|
@ -1448,3 +1449,9 @@ class CacheFTPHandler(FTPHandler):
|
|||
del self.timeout[k]
|
||||
break
|
||||
self.soonest = min(self.timeout.values())
|
||||
|
||||
def clear_cache(self):
|
||||
for conn in self.cache.values():
|
||||
conn.close()
|
||||
self.cache.clear()
|
||||
self.timeout.clear()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue