Skip to content

Make the legacy-import re-entry guard survive activity recreation#16

Merged
xroche merged 2 commits into
masterfrom
fix/import-reentry
Jul 18, 2026
Merged

Make the legacy-import re-entry guard survive activity recreation#16
xroche merged 2 commits into
masterfrom
fix/import-reentry

Conversation

@xroche

@xroche xroche commented Jul 18, 2026

Copy link
Copy Markdown
Owner

importInProgress was a per-instance field. Since the activity declares no configChanges, 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 .part file. The loser leaves a short file behind that dest.exists() treats as complete on every future run.

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 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.

xroche and others added 2 commits July 18, 2026 18:53
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>
@xroche
xroche merged commit 227b5e8 into master Jul 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant