From 521ca86efc11b641a77d21014ee611e1343d461a Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Tue, 7 Mar 2017 17:02:52 -0800 Subject: [PATCH] [client-app] Prevent `database malformed` error restart loop Summary: This error is can flood Sentry pretty badly: https://sentry.io/nylas/nylas-mail/issues/230629801/ My initial thought was to rate limit it, but rate limiting wouldn't do any good because when we get that error we destroy the databases and restart the app, and we will loose the in-memory rate limiting data. The real fix, and reason why Sentry is being flooded with this error by a single user, is that once you encounter this error the app will enter a restart loop that constantly throws this error. The reason being that we weren't properly awaiting for the K2 account databases to be dropped before closing the app, so on restart, the database would still be malformed. The fix is to properly `await` for the database drops Test Plan: manual Reviewers: spang, mark, halla, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D4127 --- .../client-sync/src/local-sync-worker/sync-process-manager.js | 2 +- packages/client-sync/src/shared/local-database-connector.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/client-sync/src/local-sync-worker/sync-process-manager.js b/packages/client-sync/src/local-sync-worker/sync-process-manager.js index 6a2e774f8..3c1efbb61 100644 --- a/packages/client-sync/src/local-sync-worker/sync-process-manager.js +++ b/packages/client-sync/src/local-sync-worker/sync-process-manager.js @@ -49,7 +49,7 @@ class SyncProcessManager { // DB fs.unlinkSync(`${NylasEnv.getConfigDirPath()}/edgehill.db`) for (const account of this.accounts()) { - LocalDatabaseConnector.destroyAccountDatabase(account.id) + await LocalDatabaseConnector.destroyAccountDatabase(account.id) } remote.app.relaunch() remote.app.quit() diff --git a/packages/client-sync/src/shared/local-database-connector.js b/packages/client-sync/src/shared/local-database-connector.js index 0d60807e6..9264366f4 100644 --- a/packages/client-sync/src/shared/local-database-connector.js +++ b/packages/client-sync/src/shared/local-database-connector.js @@ -64,7 +64,7 @@ class LocalDatabaseConnector { }); } - destroyAccountDatabase(accountId) { + async destroyAccountDatabase(accountId) { if (NylasEnv.inSpecMode()) { // The db is in memory, so we don't have to unlink it. Just drop the data. return this.forAccount(accountId).then(db => {