From 7430212ac86201ed478d3861ff3a22a2481b0575 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 11 Sep 2021 00:55:37 +0200 Subject: [PATCH] Send save list explictitly on stop Prevent ordering issues with save notifications on stop by making the save list update part of the stop action instead of some unspecificed amount of time later. This also fixes the issue of the connection being closed before the last instance sends it save list on slave shutdown. --- packages/slave/slave.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/slave/slave.js b/packages/slave/slave.js index de89a7ed..5d03bc63 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -295,10 +295,6 @@ class Instance extends libLink.Link { for (let pluginInstance of this.plugins.values()) { pluginInstance.onExit(); } - - this.sendSaveListUpdate().catch(err => { - this.logger.error(`Unexpected error updating save list:\n${err.stack}`); - }); } async _loadPlugin(pluginInfo, slave) { @@ -318,6 +314,7 @@ class Instance extends libLink.Link { await this.server.init(); } catch (err) { this.notifyExit(); + await this.sendSaveListUpdate(); throw err; } @@ -335,6 +332,7 @@ class Instance extends libLink.Link { await this._loadPlugin(pluginInfo, this._slave); } catch (err) { this.notifyExit(); + await this.sendSaveListUpdate(); throw err; } } @@ -689,6 +687,7 @@ class Instance extends libLink.Link { if (this.server._state === "running") { await libPlugin.invokeHook(this.plugins, "onStop"); await this.server.stop(); + await this.sendSaveListUpdate(); } } @@ -728,6 +727,7 @@ class Instance extends libLink.Link { saveName = await this.prepareSave(saveName); } catch (err) { this.notifyExit(); + await this.sendSaveListUpdate(); throw err; } @@ -749,6 +749,7 @@ class Instance extends libLink.Link { await this.prepare(); } catch (err) { this.notifyExit(); + await this.sendSaveListUpdate(); throw err; } @@ -779,12 +780,14 @@ class Instance extends libLink.Link { } catch (err) { this.notifyExit(); + await this.sendSaveListUpdate(); throw err; } this.server.on("exit", () => this.notifyExit()); let { name, seed, map_gen_settings, map_settings } = message.data; await this.server.create(name, seed, map_gen_settings, map_settings); + await this.sendSaveListUpdate(); this.logger.info("Successfully created save"); }