You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The socket hangup is only emitted when socket._hadError === false and the ssl error is only emitted when socket._writableState.errorEmitted === false. Therefore both get emitted.
The following patch lets onHangUp() check socket._writableState.errorEmitted in the next tick to ensure the ssl error is emitted, since the socket hangup does have less useful information.
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index fcc216b..5f93270 100644
--- a/lib/_tls_wrap.js+++ b/lib/_tls_wrap.js@@ -947,10 +947,17 @@ exports.connect = function(/* [port, host], options, cb */) {
// NOTE: This logic is shared with _http_client.js
if (!socket._hadError) {
socket._hadError = true;
- var error = new Error('socket hang up');- error.code = 'ECONNRESET';- socket.destroy();- socket.emit('error', error);++ setImmediate(function() {+ if (socket._writableState.errorEmitted)+ return;+ socket._writableState.errorEmitted = true;++ var error = new Error('socket hang up');+ error.code = 'ECONNRESET';+ socket.destroy();+ socket.emit('error', error);+ });
}
}
socket.once('end', onHangUp);
Another issue arose while checking on('close', function(hadError) {}); hadError is always false. Not sure why yet.
Activity
user447463 commentedon Mar 11, 2015
Update: It is not necessarily SNI related, as it also happens without servername being given.
skenqbx commentedon Mar 11, 2015
The socket hangup is only emitted when
socket._hadError === falseand the ssl error is only emitted whensocket._writableState.errorEmitted === false. Therefore both get emitted.The following patch lets
onHangUp()checksocket._writableState.errorEmittedin the next tick to ensure the ssl error is emitted, since the socket hangup does have less useful information.Another issue arose while checking
on('close', function(hadError) {});hadErroris alwaysfalse. Not sure why yet.Fishrock123 commentedon May 13, 2015
cc @indutny?
indutny commentedon May 15, 2015
Looking.
indutny commentedon May 15, 2015
@skenqbx this change looks good to me. May I ask you to send a PR for it? I'll send a PR for fixing the 'close' event's argument in TLS.
Many thanks!
tls: use `.destroy(err)` instead of destroy+emit
indutny commentedon May 15, 2015
@skenqbx here it is #1711
skenqbx commentedon May 18, 2015
Will do, give me until end of the week.
tls: use `.destroy(err)` instead of destroy+emit
indutny commentedon May 22, 2015
Errors are now properly reported as of 80342f6
silverwind commentedon May 22, 2015
sorry, didn't see there's still a task pending here at first.
skenqbx commentedon May 22, 2015
The double emission of errors seems to be handled by #1711.
tls: emit errors happening before handshake finish
skenqbx commentedon May 23, 2015
@silverwind This can be closed now, thank you.
tls: use `.destroy(err)` instead of destroy+emit
tls: emit errors happening before handshake finish