Fix race condition in download queue when concurrent jobs share destination directory#104
Merged
lstein merged 3 commits intolstein/bugfix/test_download_queue-failurefrom Feb 28, 2026
Conversation
Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix race condition in test_download_queue.py
Fix race condition in download queue when concurrent jobs share destination directory
Feb 28, 2026
lstein
approved these changes
Feb 28, 2026
Owner
lstein
left a comment
There was a problem hiding this comment.
Seems to work, but hard to know given that it is a race condition.
c2f4ad3
into
lstein/bugfix/test_download_queue-failure
13 checks passed
lstein
added a commit
that referenced
this pull request
Mar 6, 2026
…nation directory (#104) (invoke-ai#8931) * Initial plan * Fix race condition in _do_download when scanning for .downloading files * chore(backend): update copyright --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When two download jobs target the same destination directory simultaneously, a TOCTOU race between
glob("*.downloading")and the subsequent.stat()call could cause aFileNotFoundErrorif a concurrent job completed and renamed its.downloadingfile in between. This surfaced as an intermittent test failure intest_errorswherebroken's job error wasFileNotFoundErrorinstead of the expectedHTTPError(NOT FOUND).Fix: In
_do_download, wrap thecandidates[0].stat().st_sizecall in atry-except FileNotFoundError. If the file disappears between glob and stat, resetjob.download_path = Noneand leaveresume_from = 0so the job proceeds as a fresh download.Related Issues / Discussions
QA Instructions
Run
tests/app/services/download/test_download_queue.py::test_errorsrepeatedly — it previously failed intermittently due to this race.Merge Plan
Checklist
What's Newcopy (if doing a release after this PR)Original prompt
This section details on the original issue you should resolve
<issue_title>[bug]: Race condition in test_download_queue.py</issue_title>
<issue_description>### Is there an existing issue for this problem?
Install method
Invoke's Launcher
Operating system
Linux
GPU vendor
Nvidia (CUDA)
GPU model
No response
GPU VRAM
No response
Version number
main branch
Browser
No response
System Information
No response
What happened
I am seeing random failures of the unit test
tests/app/services/download/test_download_queue.pycrom what appears to be a race condition. Here is a typical stack trace: