Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yudongzhu opened this issue Feb 4, 2018 · 1 comment

Comments

@yudongzhu
Copy link

yudongzhu commented Feb 4, 2018

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) : '';

@Prestaul
Copy link

Prestaul commented Aug 9, 2018

This is actually a significant issue. How do we get a maintainer to put eyes on it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants