Fix pending request not deleted on response

Fix memory leak due to the recorded _pendingRequests entry for a request
not being deleted when the response for the request has been received.
This commit is contained in:
Hornwitser committed 2024-01-22 20:48:01 +01:00
1 parent d7edae99c5
commit 123148e277
3 files changed
+7

No files matched your search

+1
View File
@@ -13,6 +13,7 @@
- Fixed ctl not exporting types used for adding commands to ctl plugins.
- 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.
## Version 2.0.0-alpha.14
+2
View File
@@ -428,6 +428,7 @@ export class Link {
throw new libErrors.InvalidMessage(`Received reply from ${message.src} for message sent to ${pending.dst}`);
}
this._pendingRequests.delete(message.dst.requestId!);
try {
pending.resolve(pending.request.responseFromJSON(message.data));
} catch (err: any) {
@@ -444,6 +445,7 @@ export class Link {
);
}
this._pendingRequests.delete(message.dst.requestId!);
pending.reject(new libErrors.RequestError(message.data.message, message.data.code, message.data.stack));
}
+4
View File
@@ -16,6 +16,7 @@ describe("lib/link/link", function() {
describe("class Link", function() {
let testConnector;
/** @type {lib.Link} */
let testLink;
let src = addr({ controlId: 1 });
let dst = addr("controller");
@@ -281,6 +282,7 @@ describe("lib/link/link", function() {
let srcReq = new lib.Address(lib.Address.control, 1, 1);
testConnector.emit("message", new lib.MessageResponse(1, dst, srcReq));
await request;
assert.deepEqual(testLink._pendingRequests, new Map());
});
it("should send request and reject with error when error response is received", async function() {
let message = events.once(testConnector, "send");
@@ -297,6 +299,7 @@ describe("lib/link/link", function() {
request,
{ message: "Error" }
);
assert.deepEqual(testLink._pendingRequests, new Map());
});
it("should send request and resolve with data when response is received", async function() {
let message = events.once(testConnector, "send");
@@ -305,6 +308,7 @@ describe("lib/link/link", function() {
let srcReq = new lib.Address(lib.Address.control, 1, 1);
testConnector.emit("message", new lib.MessageResponse(1, dst, srcReq, 44));
assert.deepEqual(await request, new NumberRequest.Response(44));
assert.deepEqual(testLink._pendingRequests, new Map());
});
it("should send event to the other side of the link", async function() {
let message = events.once(testConnector, "send");