mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
up2k.js: detect broken webworkers;
the first time a file is to be hashed after a website refresh, a set of webworkers are launched for efficient parallelization in the unlikely event of a network outage exactly at this point, the workers will fail to start, and the hashing would never begin add a ping/pong sequence to smoketest the workers, and fallback to hashing on the main-thread when necessary
This commit is contained in:
parent
a9b4436cdc
commit
5ca8f0706d
|
@ -17,6 +17,8 @@ function goto_up2k() {
|
||||||
var up2k = null,
|
var up2k = null,
|
||||||
up2k_hooks = [],
|
up2k_hooks = [],
|
||||||
hws = [],
|
hws = [],
|
||||||
|
hws_ok = 0,
|
||||||
|
hws_ng = false,
|
||||||
sha_js = WebAssembly ? 'hw' : 'ac', // ff53,c57,sa11
|
sha_js = WebAssembly ? 'hw' : 'ac', // ff53,c57,sa11
|
||||||
m = 'will use ' + sha_js + ' instead of native sha512 due to';
|
m = 'will use ' + sha_js + ' instead of native sha512 due to';
|
||||||
|
|
||||||
|
@ -1964,7 +1966,7 @@ function up2k_init(subtle) {
|
||||||
pvis.setab(t.n, nchunks);
|
pvis.setab(t.n, nchunks);
|
||||||
pvis.move(t.n, 'bz');
|
pvis.move(t.n, 'bz');
|
||||||
|
|
||||||
if (hws.length && uc.hashw && (nchunks > 1 || document.visibilityState == 'hidden'))
|
if (hws.length && !hws_ng && uc.hashw && (nchunks > 1 || document.visibilityState == 'hidden'))
|
||||||
// resolving subtle.digest w/o worker takes 1sec on blur if the actx hack breaks
|
// resolving subtle.digest w/o worker takes 1sec on blur if the actx hack breaks
|
||||||
return wexec_hash(t, chunksize, nchunks);
|
return wexec_hash(t, chunksize, nchunks);
|
||||||
|
|
||||||
|
@ -2073,16 +2075,27 @@ function up2k_init(subtle) {
|
||||||
free = [],
|
free = [],
|
||||||
busy = {},
|
busy = {},
|
||||||
nbusy = 0,
|
nbusy = 0,
|
||||||
|
init = 0,
|
||||||
hashtab = {},
|
hashtab = {},
|
||||||
mem = (MOBILE ? 128 : 256) * 1024 * 1024;
|
mem = (MOBILE ? 128 : 256) * 1024 * 1024;
|
||||||
|
|
||||||
|
if (!hws_ok)
|
||||||
|
init = setTimeout(function() {
|
||||||
|
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);
|
||||||
|
st.todo.hash.unshift(t);
|
||||||
|
exec_hash();
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
for (var a = 0; a < hws.length; a++) {
|
for (var a = 0; a < hws.length; a++) {
|
||||||
var w = hws[a];
|
var w = hws[a];
|
||||||
free.push(w);
|
|
||||||
w.onmessage = onmsg;
|
w.onmessage = onmsg;
|
||||||
|
if (init)
|
||||||
|
w.postMessage('ping');
|
||||||
|
if (mem > 0)
|
||||||
|
free.push(w);
|
||||||
mem -= chunksize;
|
mem -= chunksize;
|
||||||
if (mem <= 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function go_next() {
|
function go_next() {
|
||||||
|
@ -2112,6 +2125,12 @@ function up2k_init(subtle) {
|
||||||
d = d.data;
|
d = d.data;
|
||||||
var k = d[0];
|
var k = d[0];
|
||||||
|
|
||||||
|
if (k == "pong")
|
||||||
|
if (++hws_ok == hws.length) {
|
||||||
|
clearTimeout(init);
|
||||||
|
go_next();
|
||||||
|
}
|
||||||
|
|
||||||
if (k == "panic")
|
if (k == "panic")
|
||||||
return vis_exh(d[1], 'up2k.js', '', '', d[1]);
|
return vis_exh(d[1], 'up2k.js', '', '', d[1]);
|
||||||
|
|
||||||
|
@ -2174,6 +2193,7 @@ function up2k_init(subtle) {
|
||||||
tasker();
|
tasker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!init)
|
||||||
go_next();
|
go_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,9 @@ onmessage = (d) => {
|
||||||
if (d.data == 'nosubtle')
|
if (d.data == 'nosubtle')
|
||||||
return load_fb();
|
return load_fb();
|
||||||
|
|
||||||
|
if (d.data == 'ping')
|
||||||
|
return postMessage(['pong']);
|
||||||
|
|
||||||
if (busy)
|
if (busy)
|
||||||
return postMessage(["panic", 'worker got another task while busy']);
|
return postMessage(["panic", 'worker got another task while busy']);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue