Mailspring/packages/isomorphic-core/src
Juan Tejada 00aa499365 [client-sync] Prevent duplicate accounts and sync workers
Summary:
After https://github.com/nylas/nylas-mail-all/commit/008cb4c, the shape of
account.connectionSettings changed, which means that ids for accounts
will also change, given that they are based on the connection settings (see
Account.hash()).

This is fine in most cases, except for accounts that were running on a
version of Nylas Mail before 008cb4c, then upgraded to a version
after 008cb4c, and then re-authed their account.
In this scenario, re-authing the account will create a second account with
a different `id` but with the same email address, along with an extra
sequelize database, and will start a second SyncWorker for the same
account. App-side, the `AccountStore` will correctly overwrite the first account,
so users would correctly see just 1 account in the sidebar. However, given
that 2 SyncWorkers would be running for the same account,
message ids would collide in edgehill.db and this would cause
threads to disappear from the ui as if they were being deleted.

To fix this, we need to do 2 things:

- Upon app start, we remove any duplicate accounts that might have been created due to this bug before starting any sync workers
- If we detect that we are going to create a duplicate account upon auth success, we delete the old account first. This will effectively cause sync to restart for the account.

Test Plan:
Verified problem: Checked out a commit before 008cb4c, authed an account, checked out master, re-authed account, verified that duplicate accounts are created.

Then test 2 scenarios:
- With duplicate accounts present, checked out this commit, verified that duplicate account would be removed and sync would function normally.
- With an account authed on a build before 008cb4c, checked out this commit, re-authed the account, and verified that duplicate account wouldn't be created

Reviewers: mark, halla, khamidou, spang

Reviewed By: spang

Subscribers: tomasz

Differential Revision: https://phab.nylas.com/D4425
2017-04-14 12:24:27 -07:00
..
migrations [💄] fix eslint issues before they get overwhelming 2016-12-01 15:37:48 -08:00
models [client-sync] Prevent duplicate accounts and sync workers 2017-04-14 12:24:27 -07:00
auth-helpers.es6 [cloud-workers] [send-later] Fix send later token expiration 2017-04-06 18:57:16 -07:00
backoff-schedulers.es6 [*] Move BackoffSchedulers into isomorphic-core 2017-02-17 10:11:35 -08:00
database-types.js [iso-core, cloud-*] catch JSON parse errors in DB columns 2017-04-06 18:22:29 -07:00
db-utils.es6 [cloud-*] Switch MySQL charset to utf8mb4 2017-04-06 16:25:09 -07:00
delta-stream-builder.js [cloud-*] log errors according to bunyan specs 2017-04-05 10:47:56 -07:00
env-helpers.es6 [iso-core] Increase the IMAP connection pool size 2017-03-10 13:40:37 -08:00
errors.es6 [cloud-api] Verify SMTP credentials in /auth endpoint 2017-03-28 15:47:44 -07:00
hook-increment-version-on-save.js [*] fix(deltas): Cloud-API not filtering deltas at all, refactor a few things 2016-12-01 18:41:46 -08:00
hook-transaction-log.js [local-sync] Sync draft flag from provider to K2 & exclude drafts from Edgehill 2017-01-23 20:58:32 -08:00
imap-box.es6 [client-app] Fix references to RetryableError imports 2017-03-29 15:51:09 -07:00
imap-connection-pool.es6 [isomorphic-core] Ensure IMAPConnPool uses updated account credentials 2017-04-06 10:32:42 -07:00
imap-connection.es6 [*] Revamp SSL options (including user-facing) 2017-04-05 17:49:43 -07:00
imap-errors.es6 [cloud-api] Verify SMTP credentials in /auth endpoint 2017-03-28 15:47:44 -07:00
load-models.js [local-sync] add attachments 2017-01-05 16:33:38 -08:00
message-utils.es6 [isomorphic-core] Move buildMime to MessageUtils, add includeBcc option 2017-04-11 10:49:58 -07:00
metrics-reporter.es6 [cloud-*] remove old SignalFX reporter & add docs 2017-04-05 10:51:38 -07:00
model-utils.es6 [*] MessageFactory -> MessageUtils, SendUtils -> ModelUtils 2017-04-11 10:49:30 -07:00
promise-utils.js [💄] fix eslint issues before they get overwhelming 2016-12-01 15:37:48 -08:00
sendmail-client.es6 [isomorphic-core] Move buildMime to MessageUtils, add includeBcc option 2017-04-11 10:49:58 -07:00
smtp-errors.es6 [*] Revamp SSL options (including user-facing) 2017-04-05 17:49:43 -07:00
string-utils.es6 [client-app] use debug library for DB 2017-03-30 17:26:33 -07:00
tls-utils.es6 [*] Revamp SSL options (including user-facing) 2017-04-05 17:49:43 -07:00