Skip to content

Commit 449afbc

Browse files
committed
Handle race condition in get on a mutli self-hosted runners setup
1 parent ce2f681 commit 449afbc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/scripts/unix.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ get() {
8484
if [ "$mode" = "-s" ]; then
8585
sudo curl "${curl_opts[@]}" "${links[0]}"
8686
else
87+
lock_path="$file_path.lock"
88+
until sudo mkdir "$lock_path" 2>/dev/null; do
89+
echo "Another process is downloading a file at $file_path, waiting"
90+
sleep 1
91+
done
92+
trap 'sudo rm -rf "$lock_path"' EXIT SIGINT SIGTERM
8793
for link in "${links[@]}"; do
8894
status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link")
8995
[ "$status_code" = "200" ] && break
9096
done
9197
[ "$execute" = "-e" ] && sudo chmod a+x "$file_path"
9298
[ "$mode" = "-v" ] && echo "$status_code"
99+
sudo rm -rf "$lock_path" >/dev/null 2>&1 || true
93100
fi
94101
}
95102

0 commit comments

Comments
 (0)