fix errorhandling for browser-oom

because chrome-bug 383568268 is possibly making a return soon
(observed in google-chrome 138.0.7191.0 and chromium 139.0.7205.0)
This commit is contained in:
ed 2025-05-27 15:25:09 +00:00
parent 60fb1207fc
commit 49c7124776
2 changed files with 37 additions and 3 deletions

View file

@ -1445,6 +1445,12 @@ function up2k_init(subtle) {
nw = (subtle && !MOBILE && nw > 2) ? 2 : nw;
}
var x = sread('u2hashers') || window.u2hashers;
if (x) {
console.log('u2hashers is overriding default-value ' + nw);
nw = parseInt(x);
}
for (var a = 0; a < nw; a++)
hws.push(new Worker(SR + '/.cpr/w.hash.js?_=' + TS));
@ -2213,6 +2219,7 @@ function up2k_init(subtle) {
reading = 0,
max_readers = 1,
opt_readers = 2,
failed = false,
free = [],
busy = {},
nbusy = 0,
@ -2262,6 +2269,14 @@ function up2k_init(subtle) {
tasker();
}
function go_fail() {
failed = true;
if (nbusy)
return;
apop(st.busy.hash, t);
st.bytes.finished += t.size;
}
function onmsg(d) {
d = d.data;
var k = d[0];
@ -2276,6 +2291,12 @@ function up2k_init(subtle) {
return vis_exh(d[1], 'up2k.js', '', '', d[1]);
if (k == "fail") {
var nchunk = d[1];
free.push(busy[nchunk]);
delete busy[nchunk];
nbusy--;
reading--;
pvis.seth(t.n, 1, d[1]);
pvis.seth(t.n, 2, d[2]);
console.log(d[1], d[2]);
@ -2283,9 +2304,7 @@ function up2k_init(subtle) {
got_oserr();
pvis.move(t.n, 'ng');
apop(st.busy.hash, t);
st.bytes.finished += t.size;
return;
return go_fail();
}
if (k == "ferr")
@ -2318,6 +2337,9 @@ function up2k_init(subtle) {
t.hash.push(nchunk);
pvis.hashed(t);
if (failed)
return go_fail();
if (t.hash.length < nchunks)
return nbusy < opt_readers && go_next();

View file

@ -4,6 +4,16 @@
function hex2u8(txt) {
return new Uint8Array(txt.match(/.{2}/g).map(function (b) { return parseInt(b, 16); }));
}
function esc(txt) {
return txt.replace(/[&"<>]/g, function (c) {
return {
'&': '&amp;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;'
}[c];
});
}
var subtle = null;
@ -19,6 +29,8 @@ catch (ex) {
}
function load_fb() {
subtle = null;
if (self.hashwasm)
return;
importScripts('deps/sha512.hw.js');
console.log('using fallback hasher');
}