summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSimon Rettberg2024-12-03 15:07:47 +0100
committerSimon Rettberg2024-12-03 15:07:47 +0100
commit00bf4eda2ad056d273af668462536d26c86afe3e (patch)
treee5fa7f7256d40742e3fe23ba63e72444aa31b546 /modules
parentis_debug: Refine KCL regex (diff)
downloadslx-tools-00bf4eda2ad056d273af668462536d26c86afe3e.tar.gz
slx-tools-00bf4eda2ad056d273af668462536d26c86afe3e.tar.xz
slx-tools-00bf4eda2ad056d273af668462536d26c86afe3e.zip
[download] Refine download_retry timeout logic to stay in boundsHEADmaster
The old implementation would overshoot the set --slx-time by up to 15 seconds. Fix this.
Diffstat (limited to 'modules')
-rw-r--r--modules/download.inc22
1 files changed, 14 insertions, 8 deletions
diff --git a/modules/download.inc b/modules/download.inc
index 8c717eb..46f4f14 100644
--- a/modules/download.inc
+++ b/modules/download.inc
@@ -1,25 +1,31 @@
#!/bin/ash
download() {
- curl --location --max-redirs 5 --max-time 15 --connect-timeout 2 "$@"
+ curl --location --max-redirs 5 --max-time 15 --connect-timeout 3 "$@"
}
download_retry() {
- local delay max_time start end ret
- max_time=8
+ local delay total_time start end ret timeout
+ total_time=10
ret=100
if [ "$1" = "--slx-time" ]; then
- max_time="$2"
+ total_time="$2"
shift 2
fi
+ if ! [ "$total_time" -gt 0 ]; then
+ echo "download_retry: passed timeout is not > 0" >&2
+ return 1
+ fi
start="$( date +%s )"
- for delay in 1 2 2 3 3 3 4 4 4 5 5 5 5 5 5 5 5 5 ""; do
- download "$@"
+ end="$start"
+ for delay in 0 1 1 2 2 3 3 3 4 4 4 5 5 5 5 5 5 5 5 5; do
+ timeout=$(( total_time - delay - (end - start) ))
+ [ "$timeout" -gt 0 ] || break
+ sleep "$delay"
+ download --max-time "$timeout" "$@"
ret="$?"
[ "$ret" = 0 ] && return 0
end="$( date +%s )"
- [ "$(( end - start ))" -ge "$max_time" ] && break
- [ -n "$delay" ] && sleep "$delay"
done
return "$ret"
}