From 24ce46b380341d33b375276f74bbf82539a1d5c2 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 11 Dec 2024 22:11:54 +0000 Subject: [PATCH] avoid chrome webworker OOM bug; closes #124 chrome (and chromium-based browsers) can OOM when: * the OS is Windows, MacOS, or Android (but not Linux?) * the website is hosted on a remote IP (not localhost) * webworkers are used to read files unfortunately this also applies to Android, which heavily relies on webworkers to make read-speeds anywhere close to acceptable as for android, there are diminishing returns with more than 4 webworkers (1=1x, 2=2.3x, 3=3.8x, 4=4.2x, 6=4.5x, 8=5.3x), and limiting the number of workers to ensure at least one idle core appears to sufficiently reduce the OOM probability on desktop, webworkers are only necessary for hashwasm, so limit the number of workers to 2 if crypto.subtle is available and otherwise use the nproc-1 rule for hashwasm in workers bug report: https://issues.chromium.org/issues/383568268 --- README.md | 3 +++ copyparty/web/up2k.js | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13f18400..b24138dc 100644 --- a/README.md +++ b/README.md @@ -339,6 +339,9 @@ same order here too * [Chrome issue 1352210](https://bugs.chromium.org/p/chromium/issues/detail?id=1352210) -- plaintext http may be faster at filehashing than https (but also extremely CPU-intensive) +* [Chrome issue 383568268](https://issues.chromium.org/issues/383568268) -- filereaders in webworkers can OOM / crash the browser-tab + * copyparty has a workaround which seems to work well enough + * [Firefox issue 1790500](https://bugzilla.mozilla.org/show_bug.cgi?id=1790500) -- entire browser can crash after uploading ~4000 small files * Android: music playback randomly stops due to [battery usage settings](#fix-unreliable-playback-on-android) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 4f2e2f21..afd0db9c 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -1359,7 +1359,15 @@ function up2k_init(subtle) { draw_each = good_files.length < 50; if (WebAssembly && !hws.length) { - for (var a = 0; a < Math.min(navigator.hardwareConcurrency || 4, 16); a++) + var nw = Math.min(navigator.hardwareConcurrency || 4, 16); + + if (CHROME) { + // chrome-bug 383568268 // #124 + nw = Math.max(1, (nw > 4 ? 4 : (nw - 1))); + nw = (subtle && !MOBILE && nw > 2) ? 2 : nw; + } + + for (var a = 0; a < nw; a++) hws.push(new Worker(SR + '/.cpr/w.hash.js?_=' + TS)); if (!subtle)