From 34b2eb2e333e73aea6bfdf8860f3838dde1e4bc1 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 23 Mar 2021 16:35:11 +0100 Subject: [PATCH] Fix race condition between RPC and restricted shared folders --- www/common/outer/async-store.js | 18 ++++++++++++------ www/common/outer/team.js | 5 ++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index c61e9559a..af5ac9047 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -2622,22 +2622,28 @@ define([ // "cb" is wrapped in Util.once() and may have already been called // if we have a local cache var onReady = function (clientId, returned, cb) { - console.error('READY'); store.ready = true; var proxy = store.proxy; var manager = store.manager; var userObject = store.userObject; nThen(function (waitFor) { - if (manager) { return; } if (!proxy.settings) { proxy.settings = NEW_USER_SETTINGS; } if (!proxy.friends_pending) { proxy.friends_pending = {}; } - onCacheReady(clientId, waitFor()); - manager = store.manager; - userObject = store.userObject; - }).nThen(function (waitFor) { + + // Call onCacheReady if the manager is not yet defined + if (!manager) { + onCacheReady(clientId, waitFor()); + manager = store.manager; + userObject = store.userObject; + } + + // Initialize RPC in parallel of onCacheReady in case a shared folder + // is RESTRICTED and requires RPC authentication initAnonRpc(null, null, waitFor()); initRpc(null, null, waitFor()); + + // Update loading progress postMessage(clientId, 'LOADING_DRIVE', { type: 'migrate', progress: 0 diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 7eb618d63..932e53e9f 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -351,10 +351,9 @@ define([ var team; if (!ctx.store.proxy.teams[id]) { return; } nThen(function (waitFor) { - if (ctx.cache[id]) { return; } onCacheReady(ctx, id, lm, roster, keys, cId, waitFor()); - }).nThen(function (waitFor) { - team = ctx.teams[id]; + team = ctx.teams[id] || ctx.cache[id]; + // Init Team RPC if (!keys.drive.edPrivate) { return; } initRpc(ctx, team, keys.drive, waitFor(function () {}));