From 98701b78e6324ea19f3cb6795b372435c697d06e Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 30 Nov 2025 14:57:21 +0000 Subject: [PATCH] fix worker init timeout (closes #1035); context: if webworkers fail to initialize within 5sec, up2k falls back to hashing on the main-thread instead problem: if webworkers eventually do finish init, they would then be racing the mainthread fix: disconnect webworkers if init timeout additionally, gradually extend the timeout as long as the workers are still making progress initializing --- copyparty/web/up2k.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index d4dd375d..f843431a 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -2271,11 +2271,17 @@ function up2k_init(subtle) { busy = {}, nbusy = 0, init = 0, + ninit = 0, hashtab = {}, mem = (MOBILE ? 128 : 256) * 1024 * 1024; if (!hws_ok) - init = setTimeout(function() { + init = setInterval(function() { + if (ninit < hws_ok) { + ninit = hws_ok; + return toast.inf(10, 'initializing webworkers ({0}/{1})'.format(hws_ok, hws.length), "iwwt"); + } + clearInterval(init); hws_ng = true; toast.warn(30, 'webworkers failed to start\n\nwill be a bit slower due to\nhashing on main-thread'); apop(st.busy.hash, t); @@ -2325,12 +2331,17 @@ function up2k_init(subtle) { } function onmsg(d) { + if (hws_ng) + return; + d = d.data; var k = d[0]; if (k == "pong") if (++hws_ok == hws.length) { - clearTimeout(init); + clearInterval(init); + if (toast.tag == 'iwwt') + toast.hide(); go_next(); }