Skip to content

error when newSocket is undefined in lib/_http_agent.js #13831

Closed
@k1tzu

Description

@k1tzu

in https://github.com/nodejs/node/blob/master/lib/_http_agent.js
you have the code

const newSocket = self.createConnection(options, oncreate);
...
function oncreate(err, s) {
...
if (err)
      return cb(err); 
... 
}

//cb returns us to to
this.createSocket(req, options, function(err, newSocket) {
      if (err) {
        nextTick(newSocket._handle.getAsyncId(), function() {
          req.emit('error', err);
        });
...

How can you call _handle on newSocket in case there was an error creating that newSocket?
Looks not right to me.

For example where I run into it:
I have a need in a simple custom .createConnection where I do

    this.createConnection = (options, callback) => {
    let localhandle = net._createServerHandle(options.localAddress);
    if (typeof localhandle === 'number') {
        return callback("handle creation error: "+localhandle);
    }
...

And since one of your latest releases I'm receiving this error from time to time when localhandle is an error:

TypeError: Cannot read property '_handle' of undefined
                                              at _http_agent.js:186:27
                                              at oncreate (_http_agent.js:230:14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions