From ddd1bde1b4e676ce97b0a33c21d6799be14951ab Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 11 Sep 2021 02:49:40 +0200 Subject: [PATCH] Fix bad command and request sending in subspace_storage Ignore inventory updates and orders while the instance is not in the running state to avoid sending commands before the server has started up, and also ignore orders if the connection to the master server isn't isn't online to avoid piling up requests in the buffer during session resume attempts. --- plugins/subspace_storage/instance.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/subspace_storage/instance.js b/plugins/subspace_storage/instance.js index 72b31959..985b6752 100644 --- a/plugins/subspace_storage/instance.js +++ b/plugins/subspace_storage/instance.js @@ -10,13 +10,12 @@ 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) => { - if (this.stopping) { + if (this.instance.status !== "running" || !this.slave.connected) { return; } @@ -41,7 +40,6 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin { async onStop() { clearInterval(this.pingId); - this.stopping = true; await Promise.all(this.pendingTasks); } @@ -51,6 +49,16 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin { // provide items -------------------------------------------------------------- async provideItems(items) { + if (!this.slave.connector.hasSession) { + // For now the items are voided if the master connection is + // down, which is no different from the previous behaviour. + if (this.instance.config.get("subspace_storage.log_item_transfers")) { + this.logger.verbose("Voided the following items:"); + this.logger.verbose(JSON.stringify(items)); + } + return; + } + this.info.messages.place.send(this.instance, { items, instance_id: this.instance.id, @@ -84,8 +92,8 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin { } // combinator signals --------------------------------------------------------- - async updateStorageEventHandler(message, event) { - if (this.stopping) { + async updateStorageEventHandler(message) { + if (this.instance.status !== "running") { return; } let items = message.data.items;