mirror of
https://github.com/9001/copyparty.git
synced 2026-01-12 15:52:39 -07:00
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
This commit is contained in:
parent
a28503e805
commit
98701b78e6
|
|
@ -2271,11 +2271,17 @@ function up2k_init(subtle) {
|
||||||
busy = {},
|
busy = {},
|
||||||
nbusy = 0,
|
nbusy = 0,
|
||||||
init = 0,
|
init = 0,
|
||||||
|
ninit = 0,
|
||||||
hashtab = {},
|
hashtab = {},
|
||||||
mem = (MOBILE ? 128 : 256) * 1024 * 1024;
|
mem = (MOBILE ? 128 : 256) * 1024 * 1024;
|
||||||
|
|
||||||
if (!hws_ok)
|
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;
|
hws_ng = true;
|
||||||
toast.warn(30, 'webworkers failed to start\n\nwill be a bit slower due to\nhashing on main-thread');
|
toast.warn(30, 'webworkers failed to start\n\nwill be a bit slower due to\nhashing on main-thread');
|
||||||
apop(st.busy.hash, t);
|
apop(st.busy.hash, t);
|
||||||
|
|
@ -2325,12 +2331,17 @@ function up2k_init(subtle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onmsg(d) {
|
function onmsg(d) {
|
||||||
|
if (hws_ng)
|
||||||
|
return;
|
||||||
|
|
||||||
d = d.data;
|
d = d.data;
|
||||||
var k = d[0];
|
var k = d[0];
|
||||||
|
|
||||||
if (k == "pong")
|
if (k == "pong")
|
||||||
if (++hws_ok == hws.length) {
|
if (++hws_ok == hws.length) {
|
||||||
clearTimeout(init);
|
clearInterval(init);
|
||||||
|
if (toast.tag == 'iwwt')
|
||||||
|
toast.hide();
|
||||||
go_next();
|
go_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue