Skip to content

Commit 49c7124

Browse files
committed
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)
1 parent 60fb120 commit 49c7124

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

copyparty/web/up2k.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,12 @@ function up2k_init(subtle) {
14451445
nw = (subtle && !MOBILE && nw > 2) ? 2 : nw;
14461446
}
14471447

1448+
var x = sread('u2hashers') || window.u2hashers;
1449+
if (x) {
1450+
console.log('u2hashers is overriding default-value ' + nw);
1451+
nw = parseInt(x);
1452+
}
1453+
14481454
for (var a = 0; a < nw; a++)
14491455
hws.push(new Worker(SR + '/.cpr/w.hash.js?_=' + TS));
14501456

@@ -2213,6 +2219,7 @@ function up2k_init(subtle) {
22132219
reading = 0,
22142220
max_readers = 1,
22152221
opt_readers = 2,
2222+
failed = false,
22162223
free = [],
22172224
busy = {},
22182225
nbusy = 0,
@@ -2262,6 +2269,14 @@ function up2k_init(subtle) {
22622269
tasker();
22632270
}
22642271

2272+
function go_fail() {
2273+
failed = true;
2274+
if (nbusy)
2275+
return;
2276+
apop(st.busy.hash, t);
2277+
st.bytes.finished += t.size;
2278+
}
2279+
22652280
function onmsg(d) {
22662281
d = d.data;
22672282
var k = d[0];
@@ -2276,16 +2291,20 @@ function up2k_init(subtle) {
22762291
return vis_exh(d[1], 'up2k.js', '', '', d[1]);
22772292

22782293
if (k == "fail") {
2294+
var nchunk = d[1];
2295+
free.push(busy[nchunk]);
2296+
delete busy[nchunk];
2297+
nbusy--;
2298+
reading--;
2299+
22792300
pvis.seth(t.n, 1, d[1]);
22802301
pvis.seth(t.n, 2, d[2]);
22812302
console.log(d[1], d[2]);
22822303
if (d[1] == 'OS-error')
22832304
got_oserr();
22842305

22852306
pvis.move(t.n, 'ng');
2286-
apop(st.busy.hash, t);
2287-
st.bytes.finished += t.size;
2288-
return;
2307+
return go_fail();
22892308
}
22902309

22912310
if (k == "ferr")
@@ -2318,6 +2337,9 @@ function up2k_init(subtle) {
23182337
t.hash.push(nchunk);
23192338
pvis.hashed(t);
23202339

2340+
if (failed)
2341+
return go_fail();
2342+
23212343
if (t.hash.length < nchunks)
23222344
return nbusy < opt_readers && go_next();
23232345

copyparty/web/w.hash.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
function hex2u8(txt) {
55
return new Uint8Array(txt.match(/.{2}/g).map(function (b) { return parseInt(b, 16); }));
66
}
7+
function esc(txt) {
8+
return txt.replace(/[&"<>]/g, function (c) {
9+
return {
10+
'&': '&amp;',
11+
'"': '&quot;',
12+
'<': '&lt;',
13+
'>': '&gt;'
14+
}[c];
15+
});
16+
}
717

818

919
var subtle = null;
@@ -19,6 +29,8 @@ catch (ex) {
1929
}
2030
function load_fb() {
2131
subtle = null;
32+
if (self.hashwasm)
33+
return;
2234
importScripts('deps/sha512.hw.js');
2335
console.log('using fallback hasher');
2436
}

0 commit comments

Comments
 (0)