From d21861548224e9e7707602c2a324d14976cba55c Mon Sep 17 00:00:00 2001 From: Hazem Date: Fri, 17 Mar 2023 00:41:33 +0200 Subject: [PATCH] Fix min timeout --- dist/imap.js | 3 ++- src/imap.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/imap.js b/dist/imap.js index 9fcafe8d..2972db89 100644 --- a/dist/imap.js +++ b/dist/imap.js @@ -359,7 +359,8 @@ class Imap { send(str) { const buffer = (0, _common.toTypedArray)(str).buffer; - const timeout = this.timeoutSocketLowerBound + Math.floor(buffer.byteLength * this.timeoutSocketMultiplier); + let timeout = this.timeoutSocketLowerBound + Math.floor(buffer.byteLength * this.timeoutSocketMultiplier); + timeout = timeout < this.timeoutSocketLowerBound ? this.timeoutSocketLowerBound : timeout; clearTimeout(this._socketTimeoutTimer); // clear pending timeouts this._socketTimeoutTimer = setTimeout(() => this._onError(new Error(' Socket timed out!')), timeout); // arm the next timeout diff --git a/src/imap.js b/src/imap.js index 5450958d..d5099b0c 100644 --- a/src/imap.js +++ b/src/imap.js @@ -846,7 +846,8 @@ export default class Imap { _resetSocketTimeout (byteLength) { clearTimeout(this._socketTimeoutTimer) - const timeout = this.timeoutSocketLowerBound + Math.floor((byteLength || 4096) * this.timeoutSocketMultiplier) // max packet size is 4096 bytes + let timeout = this.timeoutSocketLowerBound + Math.floor((byteLength || 4096) * this.timeoutSocketMultiplier) // max packet size is 4096 bytes + timeout = timeout < this.timeoutSocketLowerBound ? this.timeoutSocketLowerBound : timeout this._socketTimeoutTimer = setTimeout(() => this._onError(new Error(' Socket timed out!')), timeout) } }