mirror of
https://github.com/alexta69/metube.git
synced 2026-09-21 13:35:01 +00:00
Wraps Download.close() in try/finally and nulls self.status_queue so the per-download manager.Queue() proxy is released once the completed Download is retained in the done list. Previously every finished download permanently pinned one Manager-process connection, accumulating file descriptors until the instance hit 'too many open files' and self-terminated (#485, #980). Co-authored-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
This commit is contained in:
@@ -898,6 +898,40 @@ def _make_download(dq_env, *, download_type="video", status="downloading", filen
|
||||
)
|
||||
|
||||
|
||||
def test_download_close_releases_status_queue(dq_env):
|
||||
download = _make_download(dq_env)
|
||||
status_queue = MagicMock()
|
||||
proc = MagicMock()
|
||||
download.status_queue = status_queue
|
||||
download.proc = proc
|
||||
|
||||
download.close()
|
||||
|
||||
proc.close.assert_called_once()
|
||||
assert download.status_queue is None
|
||||
|
||||
|
||||
def test_download_close_releases_status_queue_without_process(dq_env):
|
||||
download = _make_download(dq_env)
|
||||
download.status_queue = MagicMock()
|
||||
|
||||
download.close()
|
||||
|
||||
assert download.status_queue is None
|
||||
|
||||
|
||||
def test_download_close_releases_status_queue_when_process_close_fails(dq_env):
|
||||
download = _make_download(dq_env)
|
||||
download.status_queue = MagicMock()
|
||||
download.proc = MagicMock()
|
||||
download.proc.close.side_effect = RuntimeError('close failed')
|
||||
|
||||
with pytest.raises(RuntimeError, match='close failed'):
|
||||
download.close()
|
||||
|
||||
assert download.status_queue is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_post_download_cleanup_clears_filename_on_error(dq_env):
|
||||
notifier = AsyncMock()
|
||||
|
||||
+5
-2
@@ -787,8 +787,11 @@ class Download:
|
||||
|
||||
def close(self):
|
||||
log.info(f"Closing download process for: {self.info.title}")
|
||||
if self.started():
|
||||
self.proc.close()
|
||||
try:
|
||||
if self.started():
|
||||
self.proc.close()
|
||||
finally:
|
||||
self.status_queue = None
|
||||
|
||||
def running(self):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user