make orphan recovery idempotent - #32
Merged
Merged
Conversation
Recovery runs at startup and again on the monitor's run_orphan_recovery command. It minted a job id per torrent per pass, so every run added a duplicate row, and for an in-progress torrent it also started another watcher goroutine on the same hash, leaving rivals racing to import it. Reuse the row already tracking a torrent, and take a per-torrent claim in watchGameTorrent so only one watcher polls a given download.
Reusing the row is right, but Set rewrites the whole row, and under a source-preserving import finishTorrent deliberately leaves the torrent seeding. So a game already in the library is still in the category on the next pass, and recovery rewrote its completed row to completed_unorganized -- which is the status that draws the Organize button, on a game that is already organized. Pressing it imports it twice. Skip the torrent when the row it belongs to is already completed, matching the rule organizeGame's retry loop follows: completed is terminal and nothing may overwrite it.
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.
Orphan recovery runs at startup and again whenever the monitor fires
run_orphan_recovery, and it minted a fresh job id per torrent on every pass. So each run left another duplicate row, and for an in-progress torrent it also started a second watcher goroutine on the same hash, leaving both racing to import it.This reuses the row already tracking a torrent, and takes a per-torrent claim in
watchGameTorrentso only one watcher polls a given download. The claim lives in the watcher rather than the recovery loop so every caller is covered.