Make K2 recover from connectivity losses.

Summary: I've found a pretty annoying bug --- N1 would stop syncing all accounts after the Internet connection dropped. It seems that deep inside node-imap or NodeJS itself, connections aren't timing out the right way. To work around this, this diff unilaterally restarts the sync every `nextSyncIn` milliseconds.

Test Plan: Tested manually by cutting internet access and checking that K2 recovered.

Reviewers: evan, juan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3573
This commit is contained in:
Karim Hamidou 2017-01-03 16:03:27 -08:00
parent 0ac22782cf
commit 0b3e3d2f39
2 changed files with 5 additions and 2 deletions

View file

@ -21,6 +21,7 @@ const Capabilities = {
}
const ONE_HOUR_SECS = 60 * 60;
const SOCKET_TIMEOUT_SECS = 60;
class IMAPConnection extends EventEmitter {
@ -81,6 +82,7 @@ class IMAPConnection extends EventEmitter {
user: this._settings.imap_username,
password: this._settings.imap_password,
tls: this._settings.ssl_required,
socketTimeout: SOCKET_TIMEOUT_SECS,
}
// This account uses XOAuth2, and we have the client_id + refresh token

View file

@ -286,8 +286,6 @@ class SyncWorker {
}
this._syncStart = Date.now()
clearTimeout(this._syncTimer);
this._syncTimer = null;
this._interrupted = false
this._syncAttemptsWhileInProgress = 0
this._syncInProgress = true
@ -306,7 +304,9 @@ class SyncWorker {
try {
await this._account.update({syncError: null});
await this.ensureConnection();
await this.runNewSyncbackTasks();
await this._conn.runOperation(new FetchFolderList(this._account, this._logger));
// TODO prioritize syncing all of inbox first if there's a ton of folders (e.g. imap
@ -435,6 +435,7 @@ class SyncWorker {
console.log(`🔃 🔜 in ${nextSyncIn}ms`)
this._syncTimer = setTimeout(() => {
this.closeConnection();
this.syncNow({reason});
}, nextSyncIn);
}