diff options
author | Fedor Indutny <fedor.indutny@gmail.com> | 2013-11-05 18:14:28 +0400 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2013-11-05 18:14:28 +0400 |
commit | a6ddfe20d2bc256c71551b932a353d1b6491efd1 (patch) | |
tree | 9b4e413a93abf1e683d889a476cf70229d143617 /lib | |
parent | 515607a740222f9a9d25009b739bcd572720b793 (diff) | |
download | nodejs-a6ddfe20d2bc256c71551b932a353d1b6491efd1.tar.gz nodejs-a6ddfe20d2bc256c71551b932a353d1b6491efd1.tar.bz2 nodejs-a6ddfe20d2bc256c71551b932a353d1b6491efd1.zip |
tls: more accurate wrapping of connecting socket
When socket, passed in `tls.connect()` `options` argument is not yet
connected to the server, `_handle` gets assigned to a `net.Socket`,
instead of `TLSSocket`.
When socket is connecting to the remote server (i.e. not yet connected,
but already past dns resolve phase), derive `_connecting` property from
it, because otherwise `afterConnect()` will throw an assertion.
fix #6443
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_tls_wrap.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 3bfe98921..dbf55cea1 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -158,6 +158,10 @@ function TLSSocket(socket, options) { writable: socket.writable }); + // To prevent assertion in afterConnect() + if (socket) + this._connecting = socket._connecting; + this._tlsOptions = options; this._secureEstablished = false; this._controlReleased = false; @@ -716,10 +720,21 @@ exports.connect = function(/* [port, host], options, cb */) { result = socket; } - if (socket._handle) + if (socket._handle && !socket._connecting) { onHandle(); - else + } else { + // Not even started connecting yet (or probably resolving dns address), + // catch socket errors and assign handle. + if (!legacy && options.socket) { + options.socket.once('connect', function() { + assert(options.socket._handle); + socket._handle = options.socket._handle; + socket._handle.owner = socket; + socket.emit('connect'); + }); + } socket.once('connect', onHandle); + } if (cb) result.once('secureConnect', cb); |