Offline build: retry a stalled Geofabrik download (3 attempts, 120 s read timeout) and report network errors as a BuildError; a timed-out Last-Modified HEAD no longer fails the build
CI / check (push) Successful in 8m50s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-24 14:27:29 +01:00
1 parent 637f739e18
commit b98a3ebcf1
2 files changed
+36 -3

No files matched your search

+19 -3
View File
@@ -522,13 +522,20 @@ module Maptool
# meta / update-check below. Geofabrik 302s (e.g. .../europe/austria
# redirecting to wherever actually serves it) — followed manually
# since request_get's block form doesn't do this itself.
def self.download_extract(url, dest, limit: 5)
# Geofabrik's mirrors stall now and then (Net::ReadTimeout after 60 s
# without a byte); a stall shouldn't fail an hour-long build, so the
# download starts over a few times before giving up.
# ponytail: restarts from zero, add a Range resume if multi-GB extracts keep stalling.
NETWORK_ERRORS = [Net::OpenTimeout, Net::ReadTimeout, EOFError, IOError, SocketError, SystemCallError, OpenSSL::SSL::SSLError].freeze
DOWNLOAD_ATTEMPTS = 3
def self.download_extract(url, dest, limit: 5, attempt: 1)
raise BuildError, "too many redirects downloading #{url}" if limit.zero?
uri = URI(url)
last_modified = nil
redirect_to = nil
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", read_timeout: 120) do |http|
# Net::HTTP's default (true) quietly accepts a body cut short of
# its Content-Length; a dropped connection must fail the download.
http.ignore_eof = false
@@ -556,6 +563,11 @@ module Maptool
return download_extract(redirect_to, dest, limit: limit - 1) if redirect_to
last_modified
rescue *NETWORK_ERRORS => e
raise BuildError, "downloading #{url} failed #{attempt}× (#{e.class})" if attempt >= DOWNLOAD_ATTEMPTS
sleep 10 * attempt
download_extract(url, dest, limit: limit, attempt: attempt + 1)
end
# Sidecar recording which Geofabrik sources (country code, slug, and
@@ -597,7 +609,11 @@ module Maptool
raise BuildError, "too many redirects reaching #{url}" if limit.zero?
uri = URI(url)
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.head(uri) }
response = begin
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.head(uri) }
rescue *NETWORK_ERRORS => e
raise BuildError, "could not reach #{url} (#{e.class})"
end
case response
when Net::HTTPSuccess then response["last-modified"]
when Net::HTTPRedirection then fetch_geofabrik_last_modified(URI.join(url, response["location"]).to_s, limit: limit - 1)