mirror of https://github.com/scrapy/scrapy.git
fix(ftp): close FTP client connection and protocol on all code paths
FTPDownloadHandler.download_request() creates an FTPClient via ClientCreator.connectTCP() but never calls loseConnection(), leaking the TCP connection. Additionally, the ReceivedDataProtocol is not closed on the CommandFailed error path, leaking file handles or memory buffers. Move protocol.close() into a finally block and add client.loseConnection() there so both resources are always cleaned up regardless of success or failure. Fixes #7602
This commit is contained in:
parent
b78ab3d6c8
commit
c9ab27e281
|
|
@ -119,7 +119,9 @@ class FTPDownloadHandler(BaseDownloadHandler):
|
|||
httpcode = self.CODE_MAPPING.get(ftpcode, self.CODE_MAPPING["default"])
|
||||
return Response(url=request.url, status=httpcode, body=message.encode())
|
||||
raise
|
||||
protocol.close()
|
||||
finally:
|
||||
protocol.close()
|
||||
client.loseConnection()
|
||||
headers = {"local filename": protocol.filename or b"", "size": protocol.size}
|
||||
body = protocol.filename or protocol.body.read()
|
||||
respcls = responsetypes.from_args(url=request.url, body=body)
|
||||
|
|
|
|||
Loading…
Reference in New Issue