Prevent shutdown running more than once

Exit immediately if shutdown has already been called.  This is due to
the possibility of it being called multiple times from combinations of
signals and fatal errors.
This commit is contained in:
Hornwitser committed 2021-02-17 17:48:05 +01:00
1 parent 99fa6b4b12
commit 4ca092f351
2 files changed
+9 -1

No files matched your search

+6 -1
View File
@@ -477,11 +477,16 @@ async function saveUsers(databaseDirectory, file) {
await fs.outputFile(filePath, JSON.stringify(serialized, null, 4)); await fs.outputFile(filePath, JSON.stringify(serialized, null, 4));
} }
let shuttingDown = false;
/** /**
* Innitiate shutdown of master server * Innitiate shutdown of master server
*/ */
async function shutdown() { async function shutdown() {
logger.info("Shutting down"); if (shuttingDown) {
return;
}
shuttingDown = true;
let exitStartTime = Date.now(); let exitStartTime = Date.now();
try { try {
logger.info("Saving configs"); logger.info("Saving configs");
+3
View File
@@ -1384,6 +1384,9 @@ class Slave extends libLink.Link {
* Stops all instances and closes the connection * Stops all instances and closes the connection
*/ */
async shutdown() { async shutdown() {
if (this._shuttingDown) {
return;
}
this._shuttingDown = true; this._shuttingDown = true;
this.connector.setTimeout(30); this.connector.setTimeout(30);