tls: handle errors on socket before releasing it
Fix sudden uncatchable ECONNRESETs, when using https server.
This commit is contained in:
parent
2669966e76
commit
c50750e1fd
@ -144,6 +144,8 @@ function TLSSocket(socket, options) {
|
|||||||
this.authorized = false;
|
this.authorized = false;
|
||||||
this.authorizationError = null;
|
this.authorizationError = null;
|
||||||
|
|
||||||
|
this.on('error', this._tlsError);
|
||||||
|
|
||||||
if (!this._handle)
|
if (!this._handle)
|
||||||
this.once('connect', this._init.bind(this));
|
this.once('connect', this._init.bind(this));
|
||||||
else
|
else
|
||||||
@ -234,6 +236,13 @@ TLSSocket.prototype._tlsError = function(err) {
|
|||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TLSSocket.prototype._releaseControl = function() {
|
||||||
|
if (this._controlReleased)
|
||||||
|
return;
|
||||||
|
this._controlReleased = true;
|
||||||
|
this.removeListener('error', this._tlsError);
|
||||||
|
};
|
||||||
|
|
||||||
TLSSocket.prototype._finishInit = function() {
|
TLSSocket.prototype._finishInit = function() {
|
||||||
if (process.features.tls_npn) {
|
if (process.features.tls_npn) {
|
||||||
this.npnProtocol = this.ssl.getNegotiatedProtocol();
|
this.npnProtocol = this.ssl.getNegotiatedProtocol();
|
||||||
@ -454,7 +463,7 @@ function Server(/* [options], listener */) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!socket.destroyed) {
|
if (!socket.destroyed) {
|
||||||
socket._controlReleased = true;
|
socket._releaseControl();
|
||||||
self.emit('secureConnection', socket);
|
self.emit('secureConnection', socket);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -604,7 +613,7 @@ exports.connect = function(/* [port, host], options, cb */) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function onHandle() {
|
function onHandle() {
|
||||||
socket._controlReleased = true;
|
socket._releaseControl();
|
||||||
|
|
||||||
if (options.session)
|
if (options.session)
|
||||||
socket.setSession(options.session);
|
socket.setSession(options.session);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user