mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Make the send buffer limit a config and start a new session on overflow
Add controller.max_send_buffer_size in MiB, default 64 and 0 for no limit. Close with 1013 instead of 1008 on overflow: clients treat 1008 as fatal, so a host would shut down and the web UI would log out. With 1013 the client resumes, the controller answers with invalidate since the session has ended, and the client registers a new session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
235a15b9cc
commit
ad4595a257
7 files changed
+59
-11
No files matched your search
@@ -3,8 +3,9 @@ import events from "node:events";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
import {
|
||||
TestControlConnector, TestHostConnector, TestControl, url, controlToken,
|
||||
TestControlConnector, TestHostConnector, TestControl, url, controlToken, getControl,
|
||||
} from "./index.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { ConnectionClosed, ProtocolError, PolicyViolation, AuthenticationFailed } from "@clusterio/lib";
|
||||
import { slowTest } from "../common.js";
|
||||
|
||||
@@ -92,6 +93,33 @@ describe("Integration of lib/link", function() {
|
||||
await events.once(controlConnector, "connect");
|
||||
});
|
||||
|
||||
it("should start a new session when the send buffer limit is exceeded", async function() {
|
||||
await getControl().send(new lib.ControllerConfigSetFieldRequest("controller.max_send_buffer_size", "0.01"));
|
||||
try {
|
||||
await controlConnector.connect();
|
||||
} finally {
|
||||
await getControl().send(new lib.ControllerConfigSetFieldRequest("controller.max_send_buffer_size", "64"));
|
||||
}
|
||||
|
||||
// Never acknowledge received messages
|
||||
controlConnector._doHeartbeat = function() {
|
||||
this._sendInternal(new lib.MessageHeartbeat());
|
||||
};
|
||||
let invalidated = false;
|
||||
controlConnector.once("invalidate", () => { invalidated = true; });
|
||||
const connected = events.once(controlConnector, "invalidate").then(
|
||||
() => events.once(controlConnector, "connect")
|
||||
);
|
||||
for (let i = 0; i < 100; i++) {
|
||||
if (invalidated) {
|
||||
break;
|
||||
}
|
||||
await control.send(new lib.ControllerConfigGetRequest()).catch(() => {});
|
||||
}
|
||||
assert(invalidated, "session was not invalidated");
|
||||
await connected;
|
||||
});
|
||||
|
||||
it("should properly close connector if close is called during reconnect wait", async function() {
|
||||
await controlConnector.connect();
|
||||
controlConnector._socket.close(ConnectionClosed.Normal, "Test");
|
||||
|
||||
@@ -65,7 +65,7 @@ describe("lib/link/connectors", function() {
|
||||
|
||||
describe("send buffer limit", function() {
|
||||
afterEach(function() {
|
||||
testConnector.maxSendBufferSize = Infinity;
|
||||
testConnector.maxSendBufferSize = 0;
|
||||
testConnector._closing = false;
|
||||
});
|
||||
it("should keep unacknowledged messages under the limit", function() {
|
||||
|
||||
Reference in new issue
Block a user