From 3f9495f19d6055fca076d301bfa46a5b6e94aae4 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Wed, 21 Apr 2021 12:20:29 +0100 Subject: [PATCH] Fix event index passphrase change process --- src/electron-main.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/electron-main.js b/src/electron-main.js index 47c4e19..d0abd72 100644 --- a/src/electron-main.js +++ b/src/electron-main.js @@ -100,6 +100,12 @@ if (argv["help"]) { app.exit(); } +function delay(timeout) { + return new Promise(res => { + setTimeout(() => res(), timeout); + }); +} + // Electron creates the user data directory (with just an empty 'Dictionaries' directory...) // as soon as the app path is set, so pick a random path in it that must exist if it's a // real user data directory. @@ -596,8 +602,15 @@ ipcMain.on('seshat', async function(ev, payload) { // index. await eventIndex.changePassphrase(newPassphrase); + // Keep this delay to avoid race conditions where the DB + // lock has not been released properly when trying to + // create a new event index + await delay(500); + // Re-open the event index with the new passphrase. - eventIndex = new Seshat(eventStorePath, {newPassphrase}); + eventIndex = new Seshat(eventStorePath, { + passphrase: newPassphrase, + }); } catch (e) { sendError(payload.id, e); return;