From 664f53b75df4228cb583f9411904c20898efd180 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 30 Jun 2021 19:26:06 +0200 Subject: [PATCH] chrome gets stuck iterating over aux.h on win10 --- copyparty/web/up2k.js | 42 +++++++++++++++++++++++++++++++++++++++--- copyparty/web/util.js | 5 +++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 1e3b92ae..8e45d5d4 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -598,14 +598,50 @@ function up2k_init(subtle) { } } - function read_dirs(rd, pf, dirs, good, bad) { + function rd_flatten(pf, dirs) { + var ret = jcp(pf); + for (var a = 0; a < dirs.length; a++) + ret.push(dirs.fullPath || ''); + + ret.sort(); + return ret; + } + + var rd_missing_ref = []; + function read_dirs(rd, pf, dirs, good, bad, spins) { + spins = spins || 0; + if (++spins == 5) + rd_missing_ref = rd_flatten(pf, dirs); + + if (spins == 200) { + var missing = rd_flatten(pf, dirs), + match = rd_missing_ref.length == missing.length, + aa = match ? missing.length : 0; + + missing.sort(); + for (var a = 0; a < aa; a++) + if (rd_missing_ref[a] != missing[a]) + match = false; + + if (match) { + var msg = ['directory iterator got stuck on the following {0} items; good chance your browser is about to spinlock:'.format(missing.length)]; + for (var a = 0; a < Math.min(20, missing.length); a++) + msg.push(missing[a]); + + alert(msg.join('\n-- ')); + dirs = []; + pf = []; + } + spins = 0; + } + if (!dirs.length) { if (!pf.length) return gotallfiles(good, bad); console.log("retry pf, " + pf.length); setTimeout(function () { - read_dirs(rd, pf, dirs, good, bad); + read_dirs(rd, pf, dirs, good, bad, spins); }, 50); return; } @@ -645,7 +681,7 @@ function up2k_init(subtle) { dirs.shift(); rd = null; } - return read_dirs(rd, pf, dirs, good, bad); + return read_dirs(rd, pf, dirs, good, bad, spins); }); } diff --git a/copyparty/web/util.js b/copyparty/web/util.js index a354a1d3..5bb42cb4 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -389,6 +389,11 @@ function has(haystack, needle) { } +function jcp(obj) { + return JSON.parse(JSON.stringify(obj)); +} + + function sread(key) { if (window.localStorage) return localStorage.getItem(key);