Browse Source

tls: handle errors on socket before releasing it

Fix sudden uncatchable ECONNRESETs, when using https server.
v0.11.6-release
Fedor Indutny 12 years ago
parent
commit
c50750e1fd
  1. 13
      lib/_tls_wrap.js

13
lib/_tls_wrap.js

@ -144,6 +144,8 @@ function TLSSocket(socket, options) {
this.authorized = false;
this.authorizationError = null;
this.on('error', this._tlsError);
if (!this._handle)
this.once('connect', this._init.bind(this));
else
@ -234,6 +236,13 @@ TLSSocket.prototype._tlsError = function(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() {
if (process.features.tls_npn) {
this.npnProtocol = this.ssl.getNegotiatedProtocol();
@ -454,7 +463,7 @@ function Server(/* [options], listener */) {
}
if (!socket.destroyed) {
socket._controlReleased = true;
socket._releaseControl();
self.emit('secureConnection', socket);
}
});
@ -604,7 +613,7 @@ exports.connect = function(/* [port, host], options, cb */) {
});
function onHandle() {
socket._controlReleased = true;
socket._releaseControl();
if (options.session)
socket.setSession(options.session);

Loading…
Cancel
Save