Git Product home page Git Product logo

forever-agent's Issues

check for req.chunkedEncoding rather than req.useChunkedEncodingByDefault

When investigating why connections were being created and destroyed constantly I noticed that forever-agent looks at the request's useChunkedEncodingByDefault property rather than it's chunkedEncoding property, which seems to actually say if the request is chunked or not. Is there a reason for this?

In this screenshot you can see:

  • there are 9 free sockets available
  • there are 10 total sockets open
  • the request is not chunkedEncoded
  • it still creates a new socket

screen-shot-2014-02-26-at-11 58 36-am

bug in getConnectionName

I am using it with newer version of node and facing problem with following code of getConnectionName function in index.js.

name = host.host + ':' + host.port + ':' + (host.localAddress ? (host.localAddress + ':') : ':')

Why appending 2 colons after port number when localAddress is not present.
name getting created for my following host object is "abcd.com:80::"
{ path: undefined,
port: 80,
host: 'abcd.com',
minSockets: 10,
maxSockets: 100,
servername: 'abcd.com',
_agentKey: 'abcd.com:80:',
encoding: null
}

Too much intimacy between this, request, and http.Agent

ForeverAgent has a addRequest method, and also an addRequestnoreuse method. This overrides the http.Agent's addRequest method.

I'd really like to change the signature of agent.addRequest so that it takes an options object rather than a set of positional arguments. The reason for this is that it would allow us to reuse more of the code between http and https, where there are many more things that separate reusability buckets than just the host and port. You can reuse connections with https, but only if all the following fields are matching: host, port, ca, cert, ciphers, key, passphrase, pfx, and rejectUnauthorized.

However, because request and forever-agent use this undocumented API, we can't change it, and it'll break on the upgrade to 0.12. Making things worse, you can't chnage forever-agent's API, because request dives into its guts and sniffs for a addRequestnoreuse method.

Is there any way to refactor this so that it doesn't rely on internals in this way? What if I open source the new 0.12 http.Agent that has built-in keepAlive if you turn it on?

minSockets confusion

While using let's say ForeverAgent({maxSockets: 5}) is clear (allocate up to 5 sockets), in order to create a pool with exactly one socket I need to pass options {maxSockets: 1, minSockets: 2} as minSockets means something like "minimal amount of sockets to be kept in the pool" + 1.

Changing < to <= in https://github.com/mikeal/forever-agent/blob/master/index.js#L22 will fix it, however I understand that doing that will affect current users, so if that is not possible clarification in the doc will be good enough.

Module intention clarification

Just wanted to be clear that this module is intended to use the keep alive connection for multiple requests, thus using fewer sockets on the machine?

Cannot instantiate ForeverAgent

The constructor has this:
self.on('free', function(socket, host, port) { //...etc

EventEmitter is not in the prototype chain so it errors:
Object #<Object> has no method 'on'

package.json missing

why is there no package.json ? how did you upload it to npm without a package.json ? either i am missing something or you forgot to upload package.json ?

socket.setTimeout for foreverAgent

What would be the best way to call socket.setTimeout?

This would be from the request level, i.e.,

var request = require('request')
request.agent.timeout = 30 * 1000

Error EONT when using ForeverAgent

I have the following case:

var request = require('request');
var ForeverAgent = require('forever-agent');
var agent = new ForeverAgent();

request("http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8", {agent:agent}, function(err, response){
    console.log(err);
    console.log(response);
    console.log(err);
});

request("http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8", function(err, response){
    console.log(err);
    console.log(response);
    console.log(err);
});

In the first request block I get the following error:

{ [Error: connect ENOENT /adaptive/wowzaid3/playlist.m3u8]
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'connect',
  address: '/adaptive/wowzaid3/playlist.m3u8' }

While the second without forever agent returns a response as expected. I believe this is an issue with ForeverAgent, unless my implementation or understanding of ForeverAgent's use is wrong here?

forever-agent blocks with maxSocket=1 and POST message

Hi
For a specific test, we need to make sure that two subsequent requests use the same connection.
So, I use forever-agent with request module and it works great if the two requests are GET.

Now if the second request is a POST, the second request is never sent and it blocks forever.

After some investigations, I see that in the pb is in 'addRequest':
in the case of POST, the code does not enter the logic to reuse socket, but calls parent method addRequestNoreuse.

The reason is the test on 'req.useChunkedEncodingByDefault', which is set to true in case of a POST.

      if (this.freeSockets[name] && this.freeSockets[name].length > 0 
          && !req.useChunkedEncodingByDefault) {

If I remove this test, it works fine.

So, of course I could patch the forever-agent to do what I want, but I was wondering

  • if there is a clean solution to this pb (apparently, we cannot set the value useChunkedEncodingByDefault ourselves on the request, it is set automatically if POST is used)
  • why does the agent needs to check useChunkedEncodingByDefault ?

Thanks

Yann

Crash after trying to debug application using orientjs module

I have a rather weird setup and I am unsure where to report this.

I am using orientjs driver that apparently has something to do with forever but don't know what exactly since it's just a module.

My program runs fine with just nodemon but if I try to debug with bode-debug (frontend for node-inspector and babel) I get this:

Debugger listening on port 5858
/home/aris/code/social/server/node_modules/orientjs/node_modules/request/node_modules/forever-agent/index.js:97
ForeverAgentSSL.prototype.addRequestNoreuse = AgentSSL.prototype.addRequest
^
TypeError: Cannot read property 'prototype' of undefined
at Object. (/home/aris/code/social/server/node_modules/orientjs/node_modules/request/node_modules/forever-agent/index.js:97:55)
at Module._compile (module.js:460:26)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object. (/home/aris/code/social/server/node_modules/orientjs/node_modules/request/request.js:21:20)
at Module._compile (module.js:460:26)
at Module._extensions..js (module.js:478:10)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)

keep alive in POST request

is it possible to use open socket in POST requests? using 'request' library?

works fine for 'GET' requests, but doesn't work for POST requests

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

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

Crash inside forever agent

UNCAUGHT EXCEPTION: 'TypeError: Cannot set property 'port' of undefined\n at ForeverAgentSSL.createConnectionSSL as createConnection\n at ForeverAgentSSL.Agent.createSocket (http.js:1158:16)\n at ForeverAgentSSL.Agent.addRequest as addRequestNoreuse\n at ForeverAgentSSL.ForeverAgent.addRequest (/Users/nravicha/dev/mobile-server/node_modules/request/forever.js:58:10)\n at new ClientRequest (http.js:1279:16)\n at Object.exports.request (https.js:105:10)\n at Request.start (/Users/nravicha/dev/mobile-server/node_modules/request/main.js:559:30)\n at Request.end (/Users/nravicha/dev/mobile-server/node_modules/request/main.js:1075:28)\n at Request.init (/Users/nravicha/dev/mobile-server/node_modules/request/main.js:402:12)\n at process.startup.processNextTick.process._tickCallback (node.js:244:9)'

On debugging, I found that createConnectionSSL(port, host , options)

is being called with options as the first and only argument. port and host are already part of options as follows:
createConnectionSSL(options)

Thus, the third argument is undefined and causes the crash.

Changing function signature to createConnectionSSL (options) makes it work without issues

MIT license

Any issues with adding or making an MIT license for this package?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.