mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
Rework disconnect logic for connectors
Rework the way disconnection at shutdown is done to properly close the connections when the master server is shut down.
This commit is contained in:
1 parent
47ea8f5477
commit
9507608e59
8 files changed
+174
-44
No files matched your search
+19
-5
@@ -353,9 +353,17 @@ class Control extends link.Link {
|
||||
}
|
||||
|
||||
async shutdown() {
|
||||
await link.messages.prepareDisconnect.send(this);
|
||||
this.connector.close(1001, "Control Quit")
|
||||
await events.once(this.connector, "close");
|
||||
this.connector.setTimeout(30);
|
||||
|
||||
try {
|
||||
await link.messages.prepareDisconnect.send(this);
|
||||
} catch (err) {
|
||||
if (!(err instanceof SessionLost)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
await this.connector.close(1001, "Control Quit")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,6 +509,14 @@ async function startControl() {
|
||||
throw err;
|
||||
}
|
||||
|
||||
process.on("SIGINT", () => {
|
||||
console.log("Caught interrupt signal, closing connection");
|
||||
control.shutdown().catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
|
||||
if (commands.has(commandName)) {
|
||||
command = commands.get(commandName);
|
||||
|
||||
@@ -524,8 +540,6 @@ async function startControl() {
|
||||
await control.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
//XXX control.close("done");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in new issue
Block a user