mirror of https://github.com/scrapy/scrapy.git
Fix FTPDownloadHandler not closing FTP connection after download
download_request() created an FTPClient but never closed the control connection. Call client.transport.loseConnection() in a finally block so the TCP connection is always torn down after the transfer completes or fails. Also, the except CommandFailed path never called protocol.close(), which could leave an open file handle for local-filename downloads. Add protocol.close() at the top of the except block. Fixes #7602 Co-authored-by: Claude
This commit is contained in:
parent
dd4549e6f9
commit
7bfc2e95e9
|
|
@ -119,7 +119,10 @@ 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()
|
||||
assert client.transport
|
||||
client.transport.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