Page MenuHomePhabricator

D10681.diff
No OneTemporary

D10681.diff

diff --git a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js
--- a/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js
+++ b/lib/keyserver-conn/call-keyserver-endpoint-provider.react.js
@@ -35,10 +35,9 @@
const CallKeyserverEndpointContext: React.Context<?CallKeyserverEndpointContextType> =
React.createContext();
-let currentlyWaitingForNewCookie = false;
-let serverEndpointCallsWaitingForNewCookie: ((
- callServerEndpoint: ?CallServerEndpoint,
-) => void)[] = [];
+type OngoingRecoveryAttempt = {
+ +waitingCalls: Array<(callServerEndpoint: ?CallServerEndpoint) => mixed>,
+};
export type BindServerCallsParams = {
+dispatch: Dispatch,
@@ -55,6 +54,10 @@
+children: React.Node,
};
function CallKeyserverEndpointProvider(props: Props): React.Node {
+ const ongoingRecoveryAttemptsRef = React.useRef<
+ Map<string, OngoingRecoveryAttempt>,
+ >(new Map());
+
const bindCookieAndUtilsIntoCallServerEndpoint: (
params: BindServerCallsParams,
) => CallServerEndpoint = React.useCallback(params => {
@@ -94,13 +97,15 @@
// just let the caller callServerEndpoint instance continue
return Promise.resolve(null);
}
- if (!currentlyWaitingForNewCookie) {
+ const ongoingRecoveryAttempt =
+ ongoingRecoveryAttemptsRef.current.get(keyserverID);
+ if (!ongoingRecoveryAttempt) {
// Our cookie seems to be valid
return Promise.resolve(null);
}
// Wait to run until we get our new cookie
return new Promise<?CallServerEndpoint>(r =>
- serverEndpointCallsWaitingForNewCookie.push(r),
+ ongoingRecoveryAttempt.waitingCalls.push(r),
);
};
// This function is a helper for the next function defined below
@@ -116,9 +121,10 @@
keyserverID,
);
- currentlyWaitingForNewCookie = false;
- const currentWaitingCalls = serverEndpointCallsWaitingForNewCookie;
- serverEndpointCallsWaitingForNewCookie = [];
+ const ongoingRecoveryAttempt =
+ ongoingRecoveryAttemptsRef.current.get(keyserverID);
+ ongoingRecoveryAttemptsRef.current.delete(keyserverID);
+ const currentWaitingCalls = ongoingRecoveryAttempt?.waitingCalls ?? [];
const newCallServerEndpoint = newSessionChange
? bindCookieAndUtilsIntoCallServerEndpoint({
@@ -147,12 +153,14 @@
// user to log-in after a cookieInvalidation while logged out
return Promise.resolve(null);
}
- if (currentlyWaitingForNewCookie) {
+ const ongoingRecoveryAttempt =
+ ongoingRecoveryAttemptsRef.current.get(keyserverID);
+ if (ongoingRecoveryAttempt) {
return new Promise<?CallServerEndpoint>(r =>
- serverEndpointCallsWaitingForNewCookie.push(r),
+ ongoingRecoveryAttempt.waitingCalls.push(r),
);
}
- currentlyWaitingForNewCookie = true;
+ ongoingRecoveryAttemptsRef.current.set(keyserverID, { waitingCalls: [] });
return attemptToResolveInvalidation(sessionChange);
};

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 5:37 PM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605711
Default Alt Text
D10681.diff (3 KB)

Event Timeline