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

http core module issue #9069

Closed
the1mills opened this issue Oct 12, 2016 · 14 comments
Closed

http core module issue #9069

the1mills opened this issue Oct 12, 2016 · 14 comments
Labels
good first issue Issues that are suitable for first-time contributors. http Issues or PRs related to the http subsystem. question Issues that look for answers.

Comments

@the1mills
Copy link

the1mills commented Oct 12, 2016

on Node.js 6.7

I got this while using require('http').request()

[accounts.api.test.js]  stack: TypeError: self.agent.addRequest is not a function
[accounts.api.test.js]     at new ClientRequest (_http_client.js:158:16)
[accounts.api.test.js]     at Object.exports.request (http.js:31:10)
[accounts.api.test.js]     at Object.makeHTTPRequest [as httpHelper] (/Users/t_millal/WebstormProjects/autodesk/crucible-poc-discovery/test/helpers/http-helper.js:22:20)
[accounts.api.test.js]     at TestSuiteBase.it.cb.t (/Users/t_millal/WebstormProjects/autodesk/crucible-poc-discovery/test/test-src/accounts.api.test.js:27:17)
[accounts.api.test.js]     at /Users/t_millal/WebstormProjects/oresoftware/suman/lib/test-suite-helpers/handle-test.js:191:37
[accounts.api.test.js]     at _combinedTickCallback (internal/process/next_tick.js:67:7)
[accounts.api.test.js]     at process._tickDomainCallback (internal/process/next_tick.js:122:9)

probably shouldn't be happening no matter what the input data is, but here it is:


[accounts.api.test.js]  => request d => 
[accounts.api.test.js]  { host: 'localhost',
[accounts.api.test.js]   port: 3001,
[accounts.api.test.js]   path: '/api/Accounts',
[accounts.api.test.js]   method: 'GET',
[accounts.api.test.js]   agent: true,   <<< seems to be culprit
[accounts.api.test.js]   headers: { 'Content-Type': 'application/json' } }

curious as to what might be happening thanks, setting agent to false, will prevent this error being thrown...

@mscdex mscdex added question Issues that look for answers. http Issues or PRs related to the http subsystem. labels Oct 13, 2016
@mscdex
Copy link
Contributor

mscdex commented Oct 13, 2016

The http documentation shows valid values for the agent property. true is not one of them.

@ORESoftware
Copy link
Contributor

well shoot, maybe http should throw a better error when you pass an unacceptable value as an option..right?

@not-an-aardvark
Copy link
Contributor

If it accepts false, it seems like it should also accept true for consistency (which would be equivalent to not providing the parameter).

@ORESoftware
Copy link
Contributor

right, this is a little weird tbh

@ORESoftware
Copy link
Contributor

ORESoftware commented Oct 15, 2016

instead of false, it should accept null or undefined perhaps

@bnoordhuis bnoordhuis added the good first issue Issues that are suitable for first-time contributors. label Oct 21, 2016
@bnoordhuis
Copy link
Member

I've added the 'good first contribution' label but if no one picks it up within the next few weeks I'll go ahead and close it out as 'working as documented.'

@the1mills
Copy link
Author

the1mills commented Oct 24, 2016

Ok so more definitely, here are the current docs on this:

https://nodejs.org/api/http.html#http_http_request_options_callback

it says:

agent: Controls Agent behavior. When an Agent is used request will default to Connection: keep-alive. Possible values:

undefined (default): use http.globalAgent for this host and port.
Agent object: explicitly use the passed in Agent.
false: opts out of connection pooling with an Agent, defaults request to Connection: close.

Let's talk about the above, but as an aside, let's say we did allow agent:true, couldn't the HTTP core module deliver some "default" HTTP agent? or does it really have to be a user defined agent?

seems like you could do this:

=> http.request options =>

 { host: 'localhost',
  port: 3001,
 path: '/api/Accounts',
method: 'GET',
agent: 'default',   // if true or 'default', then HTTP core module will procure an agent with default options
 headers: { 'Content-Type': 'application/json' } }

so my thinking is here are the options:

value for "agent" option => undefined false true (new) HTTP.Agent 'default'
result same as current docs same as current docs same as 'default' same as current docs would create a new HTTP.Agent with default options

So I think passing null should throw an error (if it doesn't already). And either true should throw an error (it doesn't now) or true/'default' should create some default new HTTP.Agent. Right now the situation is not acceptable IMO.

https://nodejs.org/api/http.html#http_new_agent_options

@not-an-aardvark
Copy link
Contributor

@the1mills, thanks for putting your thoughts into this. I have a few comments on your suggested options:

So I think passing null should throw an error

I'm not sure I agree with this. I don't think we should distinguish between null and undefined as inputs, as that will lead to confusion. This would also be a breaking change, which I think is unnecessary in this case.

'default'

I'm not sure I understand the point of having an explicit option for 'default'. If someone explicitly wants to use the default behavior, they can simply omit the property and have the default behavior take effect.

In my opinion, the best course of action would be to simply allow agent: true to mean "yes, use an agent". This would nicely contrast with the existing agent: false option (which means "no agent"), and it also happens to be the same as the default behavior, which is to use an agent if agent is undefined.

@sam-github
Copy link
Contributor

I think it just makes things more weird. Having undefined (which is falsy) and false mean different things is odd, its not what someone would expect without reading the docs.

I would expect null to be falsy, and be the same as undefined or false... but that can't work: falsy like undefined, or falsy like false? Hm... I don't think there is anything we can do here that would be expected, the best thing would be to throw clear errors on any use of an invalid argument value, and expect people to read the docs.

@not-an-aardvark
Copy link
Contributor

not-an-aardvark commented Oct 24, 2016

I think agent: false semantically means "don't use an agent". agent: true semantically means "use an agent". Explicitly listing agent: undefined does seem sort of weird, and I'm not sure what it should mean, but a more common case would be omitting the agent property entirely, which triggers the default behavior.

We could use hasOwnProperty to detect whether agent: undefined is explicitly passed, but I think changing the behavior based on hasOwnProperty will be confusing. Similarly, I think treating null any differently than undefined will be confusing.

I don't think the API that I proposed above is overly confusing; if we allow agent: true, then the option is basically a boolean value that defaults to true. (This ignores the ability to pass a different agent instead of a boolean, but I think that can be considered separately.)

@sam-github
Copy link
Contributor

Well, just my opinion here, but I still think this is rearranging the deck chairs on the titanic. It isn't going to make sense when undefined and false are defined to mean the opposite of each other.

The sensible api would be:

  • no agent property: do not use an agent
  • agent: an agent object, use the agent
  • agent: http.defaultAgent, use the default agent
  • agent: true,false: not agents, throw error
  • agent: undefined: like no agent property, do not use an agent
  • agent: null: like no agent property, do not use an agent

but that's very semver major :-)

And back to the main point. @the1mills got thrown off because of a terrible error message when they used the API in a way that was plainly documented to be wrong - just a decent error message would have avoided all this, and caused the OP to check the docs.

Fixing that is a good first contribution!

@ORESoftware
Copy link
Contributor

right I was saying agent:undefined is the same as
!options.hasOwnProperty('agent'),

should result in same thing

as for agent:true, it needs to be one of three things:

~agent:false, (would not make sense at all)
~agent:undefined,
or some 3rd thing

my vote is that agent:true procures some default agent of some variety
On Oct 24, 2016 1:58 PM, "Teddy Katz" notifications@github.com wrote:

I think agent: false semantically means "don't use an agent". agent: true
semantically means "use an agent". Explicitly listing agent: undefined
does seem sort of weird, and I'm not sure what it should mean, but a more
common case would be omitting the agent property entirely, which triggers
the default behavior.

We could use hasOwnProperty to detect whether agent: undefined is
explicitly passed, but I think changing the behavior based on
hasOwnProperty will be confusing. Similarly, I think treating null any
differently than undefined will be confusing.

I don't think this API is overly confusing; if we allow agent: true, then
the option is basically a boolean value that defaults to true. (This
ignores the ability to pass a different agent instead of a boolean, but I
think that can be considered separately.)


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#9069 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AKn56It73KYeA5X9C7iItolz3K8PQRqaks5q3RvxgaJpZM4KVWCl
.

@the1mills
Copy link
Author

yeah I agree with Sam Roberts, I was talking in terms of semver minor, but
I think a major change would be warranted
On Oct 24, 2016 8:58 PM, "Sam Roberts" notifications@github.com wrote:

Well, just my opinion here, but I still think this is rearranging the deck
chairs on the titanic. It isn't going to make sense when undefined and
false are defined to mean the opposite of each other.

The sensible api would be:

  • no agent property: do not use an agent
  • agent: an agent object, use the agent
  • agent: http.defaultAgent, use the default agent
  • agent: true,false: not agents, throw error
  • agent: undefined: like no agent property, do not use an agent
  • agent: null: like no agent property, do not use an agent

but that's very semver major :-)

And back to the main point. @the1mills https://github.com/the1mills got
thrown off because of a terrible error message when they used the API in a
way that was plainly documented to be wrong - just a decent error message
would have avoided all this, and caused the OP to check the docs.

Fixing that is a good first contribution!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#9069 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACDIYCKMozwbs76xniHEZ60WTHPkIhYeks5q3X5wgaJpZM4KVWCl
.

brad-decker added a commit to brad-decker/node that referenced this issue Jan 17, 2017
As per nodejs#9069 unexpected things can happen
when supplying an unexpected value to agent.
Beings as the docs clearly state the expected
values, this throws an error on an unexpected
value.

Signed-off-by: brad-decker <bhdecker84@gmail.com>
italoacasas pushed a commit that referenced this issue Jan 18, 2017
As per #9069
unexpected things can happen when supplying an
unexpected value to agent. Beings as the docs
clearly state the expected values, this throws
an error on an unexpected value.

PR-URL: #10053
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
italoacasas pushed a commit to italoacasas/node that referenced this issue Jan 18, 2017
As per nodejs#9069
unexpected things can happen when supplying an
unexpected value to agent. Beings as the docs
clearly state the expected values, this throws
an error on an unexpected value.

PR-URL: nodejs#10053
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
@lance
Copy link
Member

lance commented Jan 19, 2017

I think the semver-major recommendation from @sam-github makes sense. But yeah... it's semver-major. In any case, it seems that this issue has been resolved with #10053 so I'm going to close this.

Please feel free to reopen if I am mistaken.

@lance lance closed this as completed Jan 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. http Issues or PRs related to the http subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

7 participants