diff --git a/imap-core/lib/imap-server.js b/imap-core/lib/imap-server.js index 4bb71a76..14f6491e 100644 --- a/imap-core/lib/imap-server.js +++ b/imap-core/lib/imap-server.js @@ -190,8 +190,10 @@ class IMAPServer extends EventEmitter { let remoteAddress = socket.remoteAddress; + let errorTimer = false; let returned = false; let onError = err => { + clearTimeout(errorTimer); if (returned) { return; } @@ -223,7 +225,10 @@ class IMAPServer extends EventEmitter { // upgrade connection let tlsSocket = new tls.TLSSocket(socket, socketOptions); - tlsSocket.once('close', onError); + let onCloseError = () => { + errorTimer = setTimeout(onError, 150); + }; + tlsSocket.once('close', onCloseError); tlsSocket.once('error', onError); tlsSocket.once('_tlsError', onError); tlsSocket.once('clientError', onError); @@ -231,7 +236,7 @@ class IMAPServer extends EventEmitter { tlsSocket.on('secure', () => { socket.removeListener('error', onError); - tlsSocket.removeListener('close', onError); + tlsSocket.removeListener('close', onCloseError); tlsSocket.removeListener('error', onError); tlsSocket.removeListener('_tlsError', onError); tlsSocket.removeListener('clientError', onError);