Concurrent chisels race on `<digest>.tmp`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Start by reading cache.go at the os.Create(c.filePath(digestKind, digest+".tmp")) call and trace how cache writes are closed, renamed, and removed on failure. Reproduce with two concurrent cuts sharing a cold cache using the supplied script. Done means concurrent fetches no longer interfere and cached blobs still match their digest.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
two chisel processes that miss the cache on the same blob at the same time write to the same temporary file, and one of them fails. the other may publish a torn file.
this happens since os.Create(c.filePath(digestKind, digest+".tmp")) in cache.go is a per-digest fixed name with no locks. with processes A and B fetching the same deb (or the same Packages index) into a cold cache:
- A creates
<digest>.tmpand starts writing. - B's
os.Createtruncates the same inode to zero. A keeps writing at its own offset, so the file has a hole of zeros at the front until B fills it. - whoever closes first hashes its own stream (correct), renames the inode to
<digest>and opens it. the other process may still be filling the hole, so the reader can see zeros where deb bytes should be;Cache.Opendoes not re-verify. - the other process finishes and its rename of
<digest>.tmpfails withno such file or directory, so the cut dies withcannot fetch from archive: rename ....
a variant: if B's download fails half way, fail removes <digest>.tmp from under A, and A's close fails the same way.
i've come across this when doing chisel-releases testing and cutting every slice of a release on every architecture. in order to make the cuts faster, arch: all debs and the per-suite indexes were shared by every worker and that's where i started getting races.
repro
two cuts at once on a cold shared cache, 20 times:
#!/usr/bin/env bash
set -e
work=$(mktemp -d)
git clone -q --depth 1 -b ubuntu-24.04 https://github.com/canonical/chisel-releases "$work/chisel-releases"
for run in $(seq 20); do
rm -rf "$work/cache" "$work"/root-* && mkdir -p "$work/root-1" "$work/root-2"
for i in 1 2; do
XDG_CACHE_HOME="$work/cache" chisel cut \
--release "$work/chisel-releases" \
--root "$work/root-$i" \
--arch amd64 base-files_base > "$work/out-$i" 2>&1 \
|| echo "run $run job $i: $(grep -m1 '^error:' "$work/out-$i")" &
done
wait # wait for both cuts
for f in "$work"/cache/chisel/sha256/[0-9a-f]*; do
[ "$(sha256sum "$f" | cut -d' ' -f1)" = "$(basename "$f")" ] \
|| echo "run $run: torn blob $(basename "$f")"
done
done
obv a bit random but in the run i've done just now 13 of the 20 runs lost one of the two cuts, every time on a Packages index (these the biggest blobs, so the race window is longest):
run 1 job 1: error: cannot fetch from archive: rename .../8f6f71ae...a30e5.tmp .../8f6f71ae...a30e5: no such file or directory
...
proposal
file, err = os.CreateTemp(c.filePath(digestKind, ""), digest+".tmp.*")
or a per-digest fslock which is what fetch does.
- Lingua principale
- Go
- Stelle
- 434
- Fork
- 74
- Merge medio
- 1g 30m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di canonical/chisel
-
`mode` of a generated directory is random when it has a generated childForse già presa @Amadeus-22 l’ha presa 24 giorni fa. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
-
cut fails on uncompressed debForse già presa @yuminn-k l’ha presa 29 giorni fa. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 42/100
-
`prefer` drops a path when the preferred package lists it `until: mutate`Forse già presa @18Abhinav07 l’ha presa 8 giorni fa. ApertaBug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
Tutte le issue di canonical/chisel
Issue simili
-
mcpx scan: flag unsafe tool namesForse già presa @zeyadbadawyy l’ha presa oggi. Apertaarea/scan enhancement good first issue priority/medium size/small
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
rohitgollarahalli/mcpx#45 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Mend: dependency security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Windows 主机
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Lee-xeo/Claude-Cage#1550 ·
I maintainer di solito rispondono entro 1 giorno
-
(bug) ui: spanPaint can index spans past their end (panic: index out of range)Forse già presa @MaxMiksa l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno