From b69a563fc205a78c0dc1699c54229e545534a707 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 18 Aug 2022 18:03:33 +0200 Subject: [PATCH] gc massage --- copyparty/web/w.hash.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/copyparty/web/w.hash.js b/copyparty/web/w.hash.js index bf1d561a..bd6e551e 100644 --- a/copyparty/web/w.hash.js +++ b/copyparty/web/w.hash.js @@ -24,6 +24,7 @@ function load_fb() { var reader = null, + gc1, gc2, gc3, busy = false; @@ -39,9 +40,14 @@ onmessage = (d) => { reader.onload = function (e) { try { + // chrome gc forgets the filereader output; remind it + gc1 = e.target.result; + gc2 = new Uint8Array(gc1, 0, 1); + gc3 = new Uint8Array(gc1, gc1.byteLength - 1); + //console.log('[ w] %d HASH bgin', nchunk); postMessage(["read", nchunk, cdr - car, Date.now() - t0]); - hash_calc(e.target.result); + hash_calc(gc1); } catch (ex) { postMessage(["panic", ex + '']); @@ -66,6 +72,11 @@ onmessage = (d) => { var hash_calc = function (buf) { var hash_done = function (hashbuf) { + // stop gc from attempting to free early + if (!gc1 || !gc2 || !gc3) + return console.log('torch went out'); + + gc1 = gc2 = gc3 = null; busy = false; try { var hslice = new Uint8Array(hashbuf).subarray(0, 33); @@ -77,6 +88,10 @@ onmessage = (d) => { } }; + // stop gc from attempting to free early + if (!gc1 || !gc2 || !gc3) + console.log('torch went out'); + if (subtle) subtle.digest('SHA-512', buf).then(hash_done); else {