Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3394118
D10681.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10681.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D10681: [lib] Track session recovery on a per-keyserver basis
Attached
Detach File
Event Timeline
Log In to Comment