Repository navigation
Conversation
… overwrite a cancel
Contributor
Author
|
@calibrain unrelated to this PR: could you turn on private vulnerability reporting for the repo (Settings, Code security, Private vulnerability reporting)? It's off right now and there's no SECURITY.md, and I have a security issue to report that shouldn't go in a public issue. I'll file it there once it's on. |
This was referenced Oct 4, 2026
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.
Kept small on purpose so it's easy to review. I have a few more small fixes like this from going back over recently merged PRs. Would you rather get them as separate PRs like this one, or combined into one?
#1361 made
cancel_downloadwrite under the queue lock, which stops a cancel from overwriting a download that finished first. The other direction is still open. The worker checkscancel_flag.is_set()and then callsupdate_status(COMPLETE)a few lines later in_process_single_download. If a cancel lands between those two lines the task goes CANCELLED, then the worker writes COMPLETE over it._apply_status_lockedallows terminal to terminal moves, so the terminal hook also fires a second time and records two events for one task.This makes the first terminal status win:
_apply_status_lockedignores a different terminal status once the task already has one. Requeueing from a terminal status still works because QUEUED isn't terminal.I replaced the existing race test. It patched
queue.update_status, whichcancel_downloadno longer calls, so it never exercised the path it names, and its last assertion only looked at the final hook event. The new tests call the queue directly: complete then cancel is refused, cancel then complete stays cancelled with one hook event, error then complete stays error, and a terminal task can still be requeued. The two late-write tests fail on currentmain.Ruff and basedpyright are clean.
tests/coreandtests/downloadpass apart from 4seleniumbaseimport failures in my environment that also fail onmain.The one red check is the existing clock-dependent test
test_a_queued_torrent_asks_for_a_grace_once, which fails on any runner that booted recently. It is fixed in #1426 and is not caused by this change.