Ignore stale replies

Summary: Changelog: ignore stale replies

Reviewed By: lblasa

Differential Revision: D32829739

fbshipit-source-id: 267f43f8e8f3dea60ee86187f7a7709fea09e5af
This commit is contained in:
Andrey Goncharov
2021-12-03 05:30:02 -08:00
committed by Facebook GitHub Bot
parent 0d94120928
commit 9fc1d3cfb9
3 changed files with 14 additions and 2 deletions

View File

@@ -97,6 +97,11 @@ class BrowserServerWebSocket extends SecureServerWebSocket {
// Upon initialization it sent a `getPlugins` request.
// We find that request and resolve it with the list of plugins we received from the `connect` message
const getPluginsCallbacks = clientConnection.matchPendingRequest(0);
if (!getPluginsCallbacks) {
return;
}
getPluginsCallbacks.resolve({
success: {plugins},
length: rawMessage.length,

View File

@@ -86,6 +86,10 @@ class SecureServerWebSocket extends ServerWebSocket {
if (isWsResponseMessage(parsedMessage)) {
const callbacks = clientConnection.matchPendingRequest(parsedMessage.id);
if (!callbacks) {
return;
}
if (parsedMessage.success !== undefined) {
callbacks.resolve({
...parsedMessage,

View File

@@ -37,11 +37,14 @@ export default class WebSocketClientConnection implements ClientConnection {
});
}
matchPendingRequest(id: number): PendingRequestResolvers {
matchPendingRequest(id: number): PendingRequestResolvers | undefined {
const callbacks = this.pendingRequests.get(id);
if (!callbacks) {
throw new Error('Pending request was not found');
console.debug(`[conn] Pending request ${id} is not found. Ignore.`);
// It must be a response for a message from the older connection. Ignore.
// TODO: When we decide to bump sdk_version, make `id` a string equal to `connectionId:messageId`. Ignore messages only from other conections. Raise an error for missing mesages from this connection.
return;
}
this.pendingRequests.delete(id);