Make the legacy-import re-entry guard survive activity recreation#16
Merged
Conversation
importInProgress was a per-instance field, so a rotation mid-import reset it while the detached worker kept copying, and the always-live Import menu let a second worker start and race the first onto the same .part file — leaving a short file that dest.exists() then treats as complete. It is now a static AtomicBoolean, claimed with compareAndSet and cleared in the worker's finally, so a recreated activity sees the in-flight import and a failing import cannot wedge the guard. The claim moved after the idempotent SAF setup so a throw there cannot wedge it either. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Review follow-up. The CAS claimed the process-wide guard, but showNotification and Thread.start() ran after it and outside the worker's try/finally. A throw there — chiefly OutOfMemoryError from thread creation under pressure — left the static guard true for the rest of the process, so every later import showed "already running" with no worker alive. The old per-instance field self-healed on the next activity; the static one does not, so the launch is now wrapped to release the guard and rethrow. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.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.
importInProgresswas a per-instance field. Since the activity declares noconfigChanges, a rotation during a long import recreated it with the flag reset while the detached worker kept copying, and the always-live Import menu then let a second worker start and race the first onto the same.partfile. The loser leaves a short file behind thatdest.exists()treats as complete on every future run.It is now a
static AtomicBoolean, claimed withcompareAndSetand cleared in the worker'sfinally, so a recreated activity sees the in-flight import and a failed import cannot wedge the guard. The claim moved after the idempotent SAF setup so a throw there cannot wedge it either.From the pre-KVM audit (finding #5, medium). The rotate-mid-import scenario needs a device to confirm end to end; the repo has no instrumentation suite.