mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Fix subspace storage sending commands during stop
Add logic to stop sending commands and wait for any pending commands to complete during instance stop in subspace_storage. This should fix the RCON connection lost errors printed in the console during stop.
This commit is contained in:
1 parent
cc438574ff
commit
1b082c6a25
1 file changed
+22
-2
@@ -10,11 +10,19 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
}
|
||||
|
||||
async init() {
|
||||
this.stopping = false;
|
||||
this.pendingTasks = new Set();
|
||||
this.instance.server.on("ipc-subspace_storage:output", (output) => {
|
||||
this.provideItems(output).catch(err => this.unexpectedError(err));
|
||||
});
|
||||
this.instance.server.on("ipc-subspace_storage:orders", (orders) => {
|
||||
this.requestItems(orders).catch(err => this.unexpectedError(err));
|
||||
if (this.stopping) {
|
||||
return;
|
||||
}
|
||||
|
||||
let task = this.requestItems(orders).catch(err => this.unexpectedError(err));
|
||||
this.pendingTasks.add(task);
|
||||
task.finally(() => { this.pendingTasks.delete(task); });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,6 +39,12 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
await this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}", true)`, true);
|
||||
}
|
||||
|
||||
async onStop() {
|
||||
clearInterval(this.pingId);
|
||||
this.stopping = true;
|
||||
await Promise.all(this.pendingTasks);
|
||||
}
|
||||
|
||||
onExit() {
|
||||
clearInterval(this.pingId);
|
||||
}
|
||||
@@ -71,13 +85,19 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
|
||||
|
||||
// combinator signals ---------------------------------------------------------
|
||||
async updateStorageEventHandler(message, event) {
|
||||
if (this.stopping) {
|
||||
return;
|
||||
}
|
||||
let items = message.data.items;
|
||||
|
||||
// XXX this should be moved to instance/clusterio api
|
||||
items.push(["signal-unixtime", Math.floor(Date.now()/1000)]);
|
||||
|
||||
let itemsJson = libLuaTools.escapeString(JSON.stringify(items));
|
||||
await this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}")`, true);
|
||||
let task = this.sendRcon(`/sc __subspace_storage__ UpdateInvData("${itemsJson}")`, true);
|
||||
this.pendingTasks.add(task);
|
||||
task.finally(() => { this.pendingTasks.delete(task); });
|
||||
await task;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user