diff options
author | Trevor Norris <trev.norris@gmail.com> | 2017-07-21 17:10:56 -0600 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-07-24 20:42:24 -0400 |
commit | 93f47b11546b2117b555695b38f505ed2779b5c3 (patch) | |
tree | 48028535912a11216f466340264ec89c55ee224c /lib/_http_agent.js | |
parent | b0a8a7c6baccea746da10e01bfb3dec18c0d723e (diff) | |
download | android-node-v8-93f47b11546b2117b555695b38f505ed2779b5c3.tar.gz android-node-v8-93f47b11546b2117b555695b38f505ed2779b5c3.tar.bz2 android-node-v8-93f47b11546b2117b555695b38f505ed2779b5c3.zip |
http: check for handle before running asyncReset()
If an uninitialized or user supplied Socket is in the freeSockets list
of the Agent it would automatically attempt to run
._handle.asyncReset(), but would throw from those not existing. Guard
against that by first checking that they exist.
PR-URL: https://github.com/nodejs/node/pull/14419
Fixes: https://github.com/nodejs/node/issues/13539
Refs: https://github.com/nodejs/node/issues/13352
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'lib/_http_agent.js')
-rw-r--r-- | lib/_http_agent.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 426cf5b502..ddd36c158e 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -167,9 +167,12 @@ Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/, if (freeLen) { // we have a free socket, so use that. var socket = this.freeSockets[name].shift(); - // Assign the handle a new asyncId and run any init() hooks. - socket._handle.asyncReset(); - socket[async_id_symbol] = socket._handle.getAsyncId(); + // Guard against an uninitialized or user supplied Socket. + if (socket._handle && typeof socket._handle.asyncReset === 'function') { + // Assign the handle a new asyncId and run any init() hooks. + socket._handle.asyncReset(); + socket[async_id_symbol] = socket._handle.getAsyncId(); + } // don't leak if (!this.freeSockets[name].length) |