Skip to content

forever-agent.getConnectionName() is different with _http_agent.getName() #42

@yudongzhu

Description

@yudongzhu

Forever-agent:
function getConnectionName(host, port) {
var name = ''
if (typeof host === 'string') {
name = host + ':' + port
} else {
// For node.js v012.0 and iojs-v1.5.1, host is an object. And any existing localAddress is part of the connection name.
name = host.host + ':' + host.port + ':' + (host.localAddress ? (host.localAddress + ':') : ':')
}
return name
}

_http_agent:
Agent.prototype.getName = function(options) {
var name = options.host || 'localhost';

name +=':';
if (options.port) name += options.port;

name += ':';
if (options.localAddress) name += options.localAddress;

if (options.family === 4 || options.family === 6)
name += ':' + options.family;

return name;
};

Here, given the parameter 'host' in forever-agent.getConnectionName() is object, then:

  1. getConnectionName() will return: 'host:port::'
    Here, it has double ':' at the end of result.
  2. getName() will return : 'host:port:'
    Here, it has only one ':' and the end of result.

The difference between these two functions will cause the forever-agent throws the error:
TypeError: Cannot read property 'length' of undefined,
at ForeverAgent/index.js:34:34

because self.sockets[name] is undefined.

Should we change to be:
name = host.host + ':' + host.port + ':' + (host.localAddress ? host.localAddress : '');
name += (host.family === 4 || host.family === 6) ? ( ':' + host.family) : '';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions