diff --git a/lib/mailbox.js b/lib/mailbox.js index d2cb9a59..ecfcaf7a 100644 --- a/lib/mailbox.js +++ b/lib/mailbox.js @@ -1746,6 +1746,12 @@ class Mailbox { } fetchCompleted = true; } catch (err) { + if (!imapClient.usable) { + // nothing to do here, connection closed + this.logger.error({ msg: `FETCH failed, connection already closed, not retrying` }); + return; + } + try { // set failure flag await this.connection.redis.hSetExists( @@ -1766,12 +1772,6 @@ class Mailbox { } // retry - if (!imapClient.usable) { - // nothing to do here, connection closed - this.logger.error({ msg: `FETCH failed, connection already closed, not retrying` }); - return; - } - let fetchRetryDelay = calculateFetchBackoff(++fetchRetryCount); this.logger.error({ msg: `FETCH failed, retrying in ${Math.round(fetchRetryDelay / 1000)}s` }); await new Promise(r => setTimeout(r, fetchRetryDelay));