From 87994fe0060ce90a9a1cd4dd67151c0c3929828d Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 24 Mar 2022 02:29:59 +0100 Subject: [PATCH] retry failed uploads with backoff --- copyparty/web/up2k.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 33bfe4ff..e1ad5720 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -1173,7 +1173,7 @@ function up2k_init(subtle) { var t = st.todo.handshake[0], cd = t.cooldown; - if (cd && cd - Date.now() > 0) + if (cd && cd > Date.now()) return false; // keepalive or verify @@ -1370,6 +1370,14 @@ function up2k_init(subtle) { return taskerd; })(); + function chill(t) { + var now = Date.now(); + if ((t.coolmul || 0) < 2 || now - t.cooldown < t.coolmul * 700) + t.coolmul = Math.min((t.coolmul || 0.5) * 2, 32); + + t.cooldown = Math.max(t.cooldown || 1, Date.now() + t.coolmul * 1000); + } + ///// //// /// hashing @@ -1756,8 +1764,12 @@ function up2k_init(subtle) { pvis.move(t.n, 'ok'); } - else t.t_uploaded = undefined; + else { + if (t.t_uploaded) + chill(t); + t.t_uploaded = undefined; + } tasker(); } else { @@ -1869,7 +1881,8 @@ function up2k_init(subtle) { else { toast.err(0, "server broke; cu-err {0} on file [{1}]:\n".format( xhr.status, t.name) + (txt || "no further information")); - return; + + chill(t); } orz2(xhr); }