Ignore stale replies
Summary: Changelog: ignore stale replies Reviewed By: lblasa Differential Revision: D32829739 fbshipit-source-id: 267f43f8e8f3dea60ee86187f7a7709fea09e5af
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0d94120928
commit
9fc1d3cfb9
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user