Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new cleanup block can cause the script to abort unexpectedly under set -u/set -e (unset TUNASYNC_WORKING_DIR and fragile find command substitution), which is a behavioral regression risk.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR prevents downstream mirrors from seeing stale Debian ftpsync “sync in progress” markers when a previous run was killed, by proactively removing old Archive-Update-in-Progress-* files at the start of a job.
Changes:
- Add a startup cleanup loop that deletes
Archive-Update-in-Progress-*markers older than 12 hours. - Log each stale marker removal to aid debugging.
| File | Description |
|---|---|
| debian.sh | Adds pre-sync cleanup of stale Archive-Update-in-Progress-* lock/marker files to avoid false “sync in progress” signals. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
bd73001 to
38f5146
Compare
|
Addressed in 38f5146: the block is now guarded against an unset TUNASYNC_WORKING_DIR, and the staleness check uses find -mmin +720 with stderr suppressed instead of a -z/-mmin -720 command substitution. |
|
Copilot review items addressed:
|
|
Round-2 review item addressed in 88602c4: the stale-lock find now uses |
happyaron
left a comment
There was a problem hiding this comment.
Thanks. One question about the failure mode first: ftpsync already takes over an existing Archive-Update-in-Progress-* lock when kill -0 <pid> fails, and its cleanup trap removes the lock at the end of that run. So a killed run's marker should normally be gone after the next sync. Is what you're seeing PID reuse after a container restart, where the stale PID matches a live process and ftpsync keeps exiting with "lock file still exists"? If so, please put that in the comment and commit message, since it's the real reason this is needed.
On the 12h threshold: the comment says any existing lock belongs to a dead run, which would justify no age limit, and the limit means up to 12h of failed runs before recovery. If you're keeping it to protect a manual or push-triggered ftpsync on the same tree, please say so in the comment.
Optional simplification. This does the same thing without the loop and avoids the set -e concerns:
find "${TUNASYNC_WORKING_DIR}" -maxdepth 1 -type f \
-name 'Archive-Update-in-Progress-*' -mmin +720 -print -delete || trueThis also assumes ftpsync's TO equals TUNASYNC_WORKING_DIR, which is worth a note in the comment.
| if find "${lock}" -type f -mmin +720 -print -quit 2>/dev/null | grep -q .; then | ||
| rm -f "${lock}" |
There was a problem hiding this comment.
Resolved in 8a2da45 by adopting the reviewer's suggested one-shot form: find "${TUNASYNC_WORKING_DIR}" -maxdepth 1 -type f -name 'Archive-Update-in-Progress-*' -mmin +720 -print -delete || true. -maxdepth 1 keeps find on the top level, so a matching directory is never descended into nor deleted (verified locally: a 13h-old Archive-Update-in-Progress-* directory containing an old file is left fully intact).
|
@happyaron Thanks for the review. All points addressed in 8a2da45:
|
If a previous ftpsync run was killed (OOM, container restart, ...), the
Archive-Update-in-Progress-* marker stays in the mirror tree and is
served to downstream mirrors, falsely signalling an ongoing sync.
ftpsync normally takes over an existing lock when kill -0 on the
recorded PID fails, but our workers run in Docker containers: a
container restart resets the PID namespace, so the stale lock's PID
can collide with a live in-container process, kill -0 succeeds, and
ftpsync keeps exiting "lock file still exists" on every run. We hit
this repeatedly at NJU and had to remove the markers manually.
Remove marker *files* older than 12h at job start with a single
find(1) call:
find "${TUNASYNC_WORKING_DIR}" -maxdepth 1 -type f \
-name 'Archive-Update-in-Progress-*' -mmin +720 -print -delete || true
Design points (from review):
- The 12h age limit protects a manual or push-triggered ftpsync
currently running on the same tree (tunasync serializes its own
jobs, but not out-of-band runs).
- `-maxdepth 1 -type f` guarantees a matching directory is neither
descended into nor deleted; `|| true` keeps a find error from
aborting the script under `set -e`/`pipefail`, and the block is
guarded for an unset/empty TUNASYNC_WORKING_DIR under `set -u`.
- Assumes ftpsync's TO equals TUNASYNC_WORKING_DIR (noted in the
script comment).
Verified locally: a 13h-old Archive-Update-in-Progress-* *directory*
containing an old file is left fully intact while stale lock files
are removed, and the block is a no-op when TUNASYNC_WORKING_DIR is
unset.
8a2da45 to
62e0850
Compare
|
Branch cleanup note: this branch has been squashed to a single commit, Review items → how they were addressed (all included in the current diff)
Some earlier in-thread replies described intermediate states of the branch; please rely on the current diff and this summary. |

If a previous ftpsync run was killed (OOM, container restart, ...), the
Archive-Update-in-Progress-*marker stays in the mirror tree and is served to downstream mirrors, falsely signalling an ongoing sync.ftpsync normally takes over an existing lock when
kill -0on the recorded PID fails — but our workers run in Docker containers, and a container restart resets the PID namespace. The stale lock's PID can then collide with a live in-container process,kill -0succeeds, and ftpsync keeps exitingUnable to start rsync, lock file still exists, PID ...on every run (ftpsync takes the lock via noclobberecho $$ > ${LOCK}, see archvsyncbin/ftpsync). We hit this repeatedly at NJU and had to remove the markers manually.The fix: remove marker files older than 12h at job start, in one
find(1)call:-maxdepth 1 -type fkeeps find on the top level, so a matching directory is never descended into nor deleted;|| trueprevents a find error from aborting the script underset -e/pipefail, and the guard keepsset -uhappy whenTUNASYNC_WORKING_DIRis unset.TOequalsTUNASYNC_WORKING_DIR(noted in the script comment).Verified locally: a 13h-old
Archive-Update-in-Progress-*directory containing an old file is left fully intact, stale lock files are removed and logged, and the block is a no-op whenTUNASYNC_WORKING_DIRis unset.