mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Fix data loss on bad name passed --dev-plugin
If data from the database is not loaded but a shutdown is triggered then the master server will overwrite the database with empty data, causing unexpected data loss. This occurs for example when the --dev-plugin option throws. Fix by setting the database entries to null before they are loaded so that should an attempt be made to save them without having been loaded first it will throw an error instead.
This commit is contained in:
1 parent
78ce6fc382
commit
a8e1971483
1 file changed
+12
-6
@@ -41,8 +41,10 @@ let loadedPlugins = {};
|
||||
let devMiddleware;
|
||||
let clusterLogger;
|
||||
let db = {
|
||||
instances: new Map(),
|
||||
slaves: new Map(),
|
||||
instances: null,
|
||||
slaves: null,
|
||||
roles: null,
|
||||
users: null,
|
||||
};
|
||||
let slaveConnections = new Map();
|
||||
let controlConnections = [];
|
||||
@@ -489,6 +491,14 @@ async function shutdown() {
|
||||
logger.info("Saving configs");
|
||||
await fs.outputFile(masterConfigPath, JSON.stringify(masterConfig.serialize(), null, 4));
|
||||
|
||||
if (devMiddleware) {
|
||||
await new Promise((resolve, reject) => { devMiddleware.close(resolve); });
|
||||
}
|
||||
|
||||
if (!db.slaves) {
|
||||
return;
|
||||
}
|
||||
|
||||
await saveMap(masterConfig.get("master.database_directory"), "slaves.json", db.slaves);
|
||||
await saveInstances(masterConfig.get("master.database_directory"), "instances.json", db.instances);
|
||||
await saveUsers(masterConfig.get("master.database_directory"), "users.json");
|
||||
@@ -497,10 +507,6 @@ async function shutdown() {
|
||||
|
||||
stopAcceptingNewSessions = true;
|
||||
|
||||
if (devMiddleware) {
|
||||
await new Promise((resolve, reject) => { devMiddleware.close(resolve); });
|
||||
}
|
||||
|
||||
let disconnectTasks = [];
|
||||
for (let controlConnection of controlConnections) {
|
||||
controlConnection.connector.setTimeout(masterConfig.get("master.connector_shutdown_timeout"));
|
||||
|
||||
Reference in new issue
Block a user