aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoronefang2019-11-04 21:20:24 +1000
committeronefang2019-11-04 21:20:24 +1000
commit58e293224ee9256937d49d3a83bf2f709f60660b (patch)
tree9c5c455a4e72e3ba5346fa466e80e50e1bd518f3
parentReduce the check exes wait time. (diff)
downloadapt-panopticon-58e293224ee9256937d49d3a83bf2f709f60660b.zip
apt-panopticon-58e293224ee9256937d49d3a83bf2f709f60660b.tar.gz
apt-panopticon-58e293224ee9256937d49d3a83bf2f709f60660b.tar.bz2
apt-panopticon-58e293224ee9256937d49d3a83bf2f709f60660b.tar.xz
End early if the host keeps timing out, and random sleep for retries.
Otherwise it could take hours trying a timing out host over and over.
-rwxr-xr-xmirror-checker.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/mirror-checker.lua b/mirror-checker.lua
index 69dd9e8..e7de781 100755
--- a/mirror-checker.lua
+++ b/mirror-checker.lua
@@ -203,6 +203,7 @@ local nlst = function (u)
203 return r and table.concat(t), e 203 return r and table.concat(t), e
204end 204end
205 205
206local timeouts = 0;
206checkHEAD = function (host, URL, r, retry) 207checkHEAD = function (host, URL, r, retry)
207 if nil == r then r = 0 end 208 if nil == r then r = 0 end
208 if nil == retry then retry = 0 end 209 if nil == retry then retry = 0 end
@@ -213,14 +214,18 @@ checkHEAD = function (host, URL, r, retry)
213 check = "Redirecting to" 214 check = "Redirecting to"
214 end 215 end
215 if 0 < retry then 216 if 0 < retry then
216-- TODO - should have a random sleep here before retrying. 217 os.execute("sleep " .. math.random(1, 4))
217 check = "Retry " .. retry .. " " .. check 218 check = "Retry " .. retry .. " " .. check
218 end 219 end
220 if 3 < timeouts then
221 E("too many timeouts! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
222 return
223 end
219 if 20 < r then 224 if 20 < r then
220 E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) 225 E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
221 return 226 return
222 end 227 end
223 if 10 < retry then 228 if 4 < retry then
224 E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) 229 E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
225 return 230 return
226 end 231 end
@@ -241,12 +246,14 @@ checkHEAD = function (host, URL, r, retry)
241 E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) 246 E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
242 -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. 247 -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth.
243 -- Might be worthwhile retrying those, some number of times. 248 -- Might be worthwhile retrying those, some number of times.
244 if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end 249 if "timeout" == c then timeouts = timeouts + 1 end
250 if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1, timeouts) end
245 else 251 else
246 if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then 252 if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then
247 E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) 253 E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
248 else 254 else
249 I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) 255 I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL)
256 timeouts = timeouts - 1 -- Backoff the timeouts count if we managed to get through.
250 end 257 end
251 l = h.location 258 l = h.location
252 if nil ~= l then 259 if nil ~= l then
@@ -295,14 +302,18 @@ local checkFiles = function (host, ip, path, file)
295 I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) 302 I(" Checking IP " .. host .. " -> " .. ip .. " " .. path)
296 for i, s in pairs(referenceDevs) do 303 for i, s in pairs(referenceDevs) do
297 if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end 304 if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end
305 if 3 < timeouts then return end
298 if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end 306 if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end
307 if 3 < timeouts then return end
299 end 308 end
300 309
301 for i, s in pairs(releases) do 310 for i, s in pairs(releases) do
302 for j, k in pairs(releaseFiles) do 311 for j, k in pairs(releaseFiles) do
303 if repoExists(s .. k) then 312 if repoExists(s .. k) then
304 if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end 313 if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end
314 if 3 < timeouts then return end
305 if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end 315 if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end
316 if 3 < timeouts then return end
306 end 317 end
307 end 318 end
308 end 319 end