mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
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:
1 parent
d7edae99c5
commit
123148e277
3 files changed
+7
No files matched your search
@@ -13,6 +13,7 @@
|
|||||||
- Fixed ctl not exporting types used for adding commands to ctl plugins.
|
- 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 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 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
|
## Version 2.0.0-alpha.14
|
||||||
|
|||||||
@@ -428,6 +428,7 @@ export class Link {
|
|||||||
throw new libErrors.InvalidMessage(`Received reply from ${message.src} for message sent to ${pending.dst}`);
|
throw new libErrors.InvalidMessage(`Received reply from ${message.src} for message sent to ${pending.dst}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._pendingRequests.delete(message.dst.requestId!);
|
||||||
try {
|
try {
|
||||||
pending.resolve(pending.request.responseFromJSON(message.data));
|
pending.resolve(pending.request.responseFromJSON(message.data));
|
||||||
} catch (err: any) {
|
} 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));
|
pending.reject(new libErrors.RequestError(message.data.message, message.data.code, message.data.stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ describe("lib/link/link", function() {
|
|||||||
|
|
||||||
describe("class Link", function() {
|
describe("class Link", function() {
|
||||||
let testConnector;
|
let testConnector;
|
||||||
|
/** @type {lib.Link} */
|
||||||
let testLink;
|
let testLink;
|
||||||
let src = addr({ controlId: 1 });
|
let src = addr({ controlId: 1 });
|
||||||
let dst = addr("controller");
|
let dst = addr("controller");
|
||||||
@@ -281,6 +282,7 @@ describe("lib/link/link", function() {
|
|||||||
let srcReq = new lib.Address(lib.Address.control, 1, 1);
|
let srcReq = new lib.Address(lib.Address.control, 1, 1);
|
||||||
testConnector.emit("message", new lib.MessageResponse(1, dst, srcReq));
|
testConnector.emit("message", new lib.MessageResponse(1, dst, srcReq));
|
||||||
await request;
|
await request;
|
||||||
|
assert.deepEqual(testLink._pendingRequests, new Map());
|
||||||
});
|
});
|
||||||
it("should send request and reject with error when error response is received", async function() {
|
it("should send request and reject with error when error response is received", async function() {
|
||||||
let message = events.once(testConnector, "send");
|
let message = events.once(testConnector, "send");
|
||||||
@@ -297,6 +299,7 @@ describe("lib/link/link", function() {
|
|||||||
request,
|
request,
|
||||||
{ message: "Error" }
|
{ message: "Error" }
|
||||||
);
|
);
|
||||||
|
assert.deepEqual(testLink._pendingRequests, new Map());
|
||||||
});
|
});
|
||||||
it("should send request and resolve with data when response is received", async function() {
|
it("should send request and resolve with data when response is received", async function() {
|
||||||
let message = events.once(testConnector, "send");
|
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);
|
let srcReq = new lib.Address(lib.Address.control, 1, 1);
|
||||||
testConnector.emit("message", new lib.MessageResponse(1, dst, srcReq, 44));
|
testConnector.emit("message", new lib.MessageResponse(1, dst, srcReq, 44));
|
||||||
assert.deepEqual(await request, new NumberRequest.Response(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() {
|
it("should send event to the other side of the link", async function() {
|
||||||
let message = events.once(testConnector, "send");
|
let message = events.once(testConnector, "send");
|
||||||
|
|||||||
Reference in new issue
Block a user