From 96bd5fb1c2879f50bfa0371b3c196f68a1266b27 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 22 Jan 2024 20:33:46 +0100 Subject: [PATCH] Handle virtual links in Link._clearPendingRequests When a request is forwarded from a virtual link to a WebSocket link as is the case when an instance sends a request to the controller the origin for the request is a virtual link. Handle this case in _clearPendingRequests instead of throwing an assertion error. --- CHANGELOG.md | 1 + packages/lib/src/link/link.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca5d9a34..bfa1c742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fixed controller only plugins throwing an error about missing a config field on startup out when added to hosts. - Fixed installer incorrectly claiming the options --factorio-dir and --no-download-headless conflicts with each other. - Fixed a memory leak on every request sent over the WebSocket. +- Fixed assertion error on closing or invalidating a link with messages forwarded from a virtual link. ## Version 2.0.0-alpha.14 diff --git a/packages/lib/src/link/link.ts b/packages/lib/src/link/link.ts index 4793008b..14b7d1ec 100644 --- a/packages/lib/src/link/link.ts +++ b/packages/lib/src/link/link.ts @@ -153,12 +153,18 @@ export class Link { pending.reject(err); } for (let pending of this._forwardedRequests.values()) { - assert(pending.origin.connector instanceof WebSocketBaseConnector); - if (pending.origin.connector.hasSession) { - pending.origin.connector.sendResponseError( - new libData.ResponseError(err.message, err.code), pending.src, pending.dst - ); + // Drop response if the origin is a WebSocket and the session + // has expired. The other end of the link will have sent an + // error response to the request in this case. + if ( + pending.origin.connector instanceof WebSocketBaseConnector + && !pending.origin.connector.hasSession + ) { + continue; } + pending.origin.connector.sendResponseError( + new libData.ResponseError(err.message, err.code), pending.src, pending.dst + ); } this._pendingRequests.clear(); this._forwardedRequests.clear();