[client-sync] Ensure we use refreshed access token for mail listener conn

Summary:
Before this commit, we would just establish a single mail listener imap
connection and never check if we needed to re-connect it due to an
expired access token. Even though we correctly refreshed the access
token at the beggining of each sync loop (hidden under
`ensureSMTPConnection`), we would never re-establish the mail listener
connection with the new access token.

This would cause the app to enter an `Invalid Credentials` error loop in
the sync loop, preventing from syncing any mail at all (T8064)

Test Plan: manual

Reviewers: spang, halla, mark, evan

Reviewed By: mark, evan

Differential Revision: https://phab.nylas.com/D4338
This commit is contained in:
Juan Tejada 2017-04-04 12:28:27 -07:00
parent 7dec807b28
commit a461490e41

View file

@ -229,9 +229,8 @@ class SyncWorker {
}
}
async _ensureSMTPConnection() {
async _ensureSMTPConnection(newCredentials) {
if (this._destroyed) { return }
const newCredentials = await this._ensureAccessToken();
if (!this._smtp || newCredentials) {
this._smtp = new SendmailClient(this._account, this._logger)
}
@ -249,9 +248,9 @@ class SyncWorker {
this._conn._db = this._db;
}
async _ensureIMAPMailListenerConnection() {
async _ensureIMAPMailListenerConnection(newCredentials) {
if (this._destroyed) { return }
if (this._mailListenerConn) {
if (!newCredentials && this._mailListenerConn) {
await this._mailListenerConn.connect();
return
}
@ -579,8 +578,9 @@ class SyncWorker {
this._logger.log(`🔃 🆕 Reason: ${reason}`)
let error;
try {
await this._ensureSMTPConnection();
await this._ensureIMAPMailListenerConnection();
const newCredentials = await this._ensureAccessToken()
await this._ensureSMTPConnection(newCredentials);
await this._ensureIMAPMailListenerConnection(newCredentials);
await IMAPConnectionPool.withConnectionsForAccount(this._account, {
desiredCount: 1,
logger: this._logger,