mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-27 02:10:52 +08:00
fix(pop3): run socket.destroy() if pop3 socket is not closed in 1.5s
This commit is contained in:
parent
8766ab9cf5
commit
2de6c0bc12
3 changed files with 33 additions and 2 deletions
|
@ -93,6 +93,8 @@ class IMAPConnection extends EventEmitter {
|
|||
this._closing = false;
|
||||
this._closed = false;
|
||||
|
||||
this._closingTimeout = null;
|
||||
|
||||
this.logger = {};
|
||||
['info', 'debug', 'error'].forEach(level => {
|
||||
this.logger[level] = (...args) => {
|
||||
|
@ -286,6 +288,7 @@ class IMAPConnection extends EventEmitter {
|
|||
|
||||
setImmediate(() => this._onClose());
|
||||
}, 1500);
|
||||
this._closingTimeout.unref();
|
||||
}
|
||||
|
||||
this._closing = true;
|
||||
|
|
|
@ -22,6 +22,7 @@ class POP3Connection extends EventEmitter {
|
|||
|
||||
this._closed = false;
|
||||
this._closing = false;
|
||||
this._closingTimeout = null;
|
||||
|
||||
this.secured = !!this._server.options.secure;
|
||||
this._upgrading = false;
|
||||
|
@ -116,6 +117,7 @@ class POP3Connection extends EventEmitter {
|
|||
* @event
|
||||
*/
|
||||
_onClose(/* hadError */) {
|
||||
clearTimeout(this._closingTimeout);
|
||||
if (this._closed) {
|
||||
return;
|
||||
}
|
||||
|
@ -138,6 +140,9 @@ class POP3Connection extends EventEmitter {
|
|||
this.remoteAddress
|
||||
);
|
||||
|
||||
// clear session
|
||||
this.session = null;
|
||||
|
||||
this.emit('close');
|
||||
}
|
||||
|
||||
|
@ -184,9 +189,32 @@ class POP3Connection extends EventEmitter {
|
|||
}
|
||||
|
||||
close() {
|
||||
if (this._closed || this._closing) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._socket.destroyed && this._socket.writable) {
|
||||
this._socket.end();
|
||||
}
|
||||
|
||||
this._server.connections.delete(this);
|
||||
|
||||
// allow socket to close in 1500ms or force it to close
|
||||
this._closingTimeout = setTimeout(() => {
|
||||
if (this._closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this._socket.destroy();
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
setImmediate(() => this._onClose());
|
||||
}, 1500);
|
||||
this._closingTimeout.unref();
|
||||
|
||||
this._closing = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
"base32.js": "0.1.0",
|
||||
"bcryptjs": "2.4.3",
|
||||
"bson": "6.1.0",
|
||||
"bullmq": "4.12.0",
|
||||
"bullmq": "4.12.1",
|
||||
"fido2-lib": "3.4.1",
|
||||
"gelf": "2.0.1",
|
||||
"generate-password": "1.7.0",
|
||||
|
@ -66,7 +66,7 @@
|
|||
"ioredis": "5.3.2",
|
||||
"ipaddr.js": "2.1.0",
|
||||
"isemail": "3.2.0",
|
||||
"joi": "17.10.2",
|
||||
"joi": "17.11.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"key-fingerprint": "1.1.0",
|
||||
"libbase64": "1.2.1",
|
||||
|
|
Loading…
Reference in a new issue