prevent potential infinite recursion on exceptions raised by event handlers

This commit is contained in:
Lincoln Stein 2023-10-12 14:34:35 -04:00
parent 0f9c676fcb
commit 53e1199902
3 changed files with 4 additions and 3 deletions

View File

@ -217,8 +217,8 @@ class ModelDownloadQueue(DownloadQueue):
return
assert isinstance(job, DownloadJobRepoID)
self._update_job_status(job, DownloadJobStatus.RUNNING)
self._lock.acquire() # prevent status from being updated while we are setting up subqueue
self._update_job_status(job, DownloadJobStatus.RUNNING)
try:
job.subqueue = self.__class__(
event_handlers=[subdownload_event],

View File

@ -402,7 +402,8 @@ class DownloadQueue(DownloadQueueBase):
raise excp
except Exception as excp:
job.error = excp
self._update_job_status(job, DownloadJobStatus.ERROR)
if job.status != DownloadJobStatus.ERROR: # let handlers know, but don't cause infinite recursion
self._update_job_status(job, DownloadJobStatus.ERROR)
def _download_path(self, job: DownloadJobBase):
"""Call when the source is a Path or pathlike object."""

View File

@ -55,7 +55,7 @@ def test_install(datadir: Path):
mm_install = ModelInstallService(config=config, store=mm_store, event_bus=event_bus)
source = datadir / TEST_MODEL
job = mm_install.install_model(source=source)
mm_install.install_model(source)
id_map = mm_install.wait_for_installs()
print(id_map)
assert source in id_map, "model did not install; id_map empty"