Skip to content

Commit 97c2336

Browse files
committed
Remove closed connections from cache
1 parent b0b636a commit 97c2336

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Lib/urllib/request.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,14 +1582,13 @@ def setMaxConns(self, m):
15821582

15831583
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
15841584
key = user, host, port, '/'.join(dirs), timeout
1585-
if key in self.cache:
1586-
self.timeout[key] = time.time() + self.delay
1587-
else:
1588-
self.cache[key] = ftpwrapper(user, passwd, host, port,
1589-
dirs, timeout)
1590-
self.timeout[key] = time.time() + self.delay
1585+
conn = self.cache.get(key)
1586+
if conn is None or not conn.keepalive:
1587+
conn = self.cache[key] = ftpwrapper(user, passwd, host, port,
1588+
dirs, timeout)
1589+
self.timeout[key] = time.time() + self.delay
15911590
self.check_cache()
1592-
return self.cache[key]
1591+
return conn
15931592

15941593
def check_cache(self):
15951594
# first check for old ones

0 commit comments

Comments
 (0)