mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +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 devMiddleware;
|
||||||
let clusterLogger;
|
let clusterLogger;
|
||||||
let db = {
|
let db = {
|
||||||
instances: new Map(),
|
instances: null,
|
||||||
slaves: new Map(),
|
slaves: null,
|
||||||
|
roles: null,
|
||||||
|
users: null,
|
||||||
};
|
};
|
||||||
let slaveConnections = new Map();
|
let slaveConnections = new Map();
|
||||||
let controlConnections = [];
|
let controlConnections = [];
|
||||||
@@ -489,6 +491,14 @@ async function shutdown() {
|
|||||||
logger.info("Saving configs");
|
logger.info("Saving configs");
|
||||||
await fs.outputFile(masterConfigPath, JSON.stringify(masterConfig.serialize(), null, 4));
|
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 saveMap(masterConfig.get("master.database_directory"), "slaves.json", db.slaves);
|
||||||
await saveInstances(masterConfig.get("master.database_directory"), "instances.json", db.instances);
|
await saveInstances(masterConfig.get("master.database_directory"), "instances.json", db.instances);
|
||||||
await saveUsers(masterConfig.get("master.database_directory"), "users.json");
|
await saveUsers(masterConfig.get("master.database_directory"), "users.json");
|
||||||
@@ -497,10 +507,6 @@ async function shutdown() {
|
|||||||
|
|
||||||
stopAcceptingNewSessions = true;
|
stopAcceptingNewSessions = true;
|
||||||
|
|
||||||
if (devMiddleware) {
|
|
||||||
await new Promise((resolve, reject) => { devMiddleware.close(resolve); });
|
|
||||||
}
|
|
||||||
|
|
||||||
let disconnectTasks = [];
|
let disconnectTasks = [];
|
||||||
for (let controlConnection of controlConnections) {
|
for (let controlConnection of controlConnections) {
|
||||||
controlConnection.connector.setTimeout(masterConfig.get("master.connector_shutdown_timeout"));
|
controlConnection.connector.setTimeout(masterConfig.get("master.connector_shutdown_timeout"));
|
||||||
|
|||||||
Reference in new issue
Block a user