From 5c023619ec7066426ce978ae7252ead97067fd98 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sun, 29 Nov 2026 17:52:02 +0100 Subject: [PATCH] Map data pull over brick's nginx: X-Accel-Buffering: no on map files (buffered, nginx's 1 GB temp file cap ended every bigger download there); each attempt resumes from the part on disk (curl's --retry kept its first offset); a file that can't be written is skipped, not the whole run --- app.rb | 4 ++++ bin/pull-maps.sh | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app.rb b/app.rb index 3eabf93..8924b9d 100644 --- a/app.rb +++ b/app.rb @@ -921,6 +921,10 @@ module Maptool get "/api/sync/maps/file" do require_sync_token! path = App.map_sync_files[params[:path].to_s] or halt 404 + # Straight through brick's nginx: buffered, it spools the response to + # a temp file capped at 1 GB (proxy_max_temp_file_size) and a bigger + # file's download ended there. + headers "X-Accel-Buffering" => "no" send_file path end diff --git a/bin/pull-maps.sh b/bin/pull-maps.sh index 03f6829..e2c2288 100755 --- a/bin/pull-maps.sh +++ b/bin/pull-maps.sh @@ -45,20 +45,28 @@ while IFS=$'\t' read -r size mtime path; do local_file="$DATA/$path" [ -f "$local_file" ] && [ "$(stat -c '%s %Y' "$local_file")" = "$size $mtime" ] && continue - mkdir -p "$(dirname "$local_file")" part="$local_file.part" + # One file that can't be written (a directory the container owns) is + # that file's failure, not the whole run's. + if ! mkdir -p "$(dirname "$local_file")" || ! touch "$part.version" 2>/dev/null; then + echo "pull-maps: can't write $local_file, skipping" >&2 + failed=$((failed + 1)) + continue + fi # A partial download of another version of the file starts over. - [ "$(cat "$part.version" 2>/dev/null)" = "$size $mtime" ] || rm -f "$part" + [ "$(cat "$part.version" 2>/dev/null)" = "$size $mtime" ] && [ "$(stat -c %s "$part" 2>/dev/null || echo 0)" -le "$size" ] || rm -f "$part" echo "$size $mtime" > "$part.version" echo "pull-maps: $path ($((size / 1048576)) MB)" # Into a temp file, renamed when complete: the app and Valhalla keep - # reading the old copy until restarted. - if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" != "$size" ]; then - # --speed-*: a connection that went dead (Wi-Fi switched, proxy gone) - # is dropped after a minute without data and the retry resumes. - curl -fsS --retry 10 --retry-all-errors --retry-delay 5 --speed-limit 1024 --speed-time 60 -C - -o "$part" -H "@$auth" \ - --get --data-urlencode "path=$path" "$server/api/sync/maps/file" || true - fi + # reading the old copy until restarted. Each attempt resumes from what's + # there (curl's own --retry keeps its first offset); --speed-*: a + # connection that went dead (Wi-Fi switched) is dropped after a minute. + stalls=0 + while have=$(stat -c %s "$part" 2>/dev/null || echo 0); [ "$have" -lt "$size" ] && [ "$stalls" -lt 5 ]; do + curl -fsS --retry 3 --retry-delay 5 --speed-limit 1024 --speed-time 60 -C - -o "$part" -H "@$auth" \ + --get --data-urlencode "path=$path" "$server/api/sync/maps/file" || sleep 5 + [ "$(stat -c %s "$part" 2>/dev/null || echo 0)" -gt "$have" ] && stalls=0 || stalls=$((stalls + 1)) + done if [ "$(stat -c %s "$part" 2>/dev/null || echo -1)" = "$size" ]; then touch -d "@$mtime" "$part" mv "$part" "$local_file"