Skip to content

Commit

Permalink
Handle race condition in get on a mutli self-hosted runners setup
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Nov 11, 2024
1 parent ce2f681 commit 449afbc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/scripts/unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@ get() {
if [ "$mode" = "-s" ]; then
sudo curl "${curl_opts[@]}" "${links[0]}"
else
lock_path="$file_path.lock"
until sudo mkdir "$lock_path" 2>/dev/null; do
echo "Another process is downloading a file at $file_path, waiting"
sleep 1
done
trap 'sudo rm -rf "$lock_path"' EXIT SIGINT SIGTERM
for link in "${links[@]}"; do
status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link")
[ "$status_code" = "200" ] && break
done
[ "$execute" = "-e" ] && sudo chmod a+x "$file_path"
[ "$mode" = "-v" ] && echo "$status_code"
sudo rm -rf "$lock_path" >/dev/null 2>&1 || true
fi
}

Expand Down

0 comments on commit 449afbc

Please sign in to comment.