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

https.request is broken by agent-base included by https-proxy-agent #2085

Closed
1 task done
davidnikdel-epic opened this issue May 24, 2019 · 18 comments · Fixed by #2108
Closed
1 task done

https.request is broken by agent-base included by https-proxy-agent #2085

davidnikdel-epic opened this issue May 24, 2019 · 18 comments · Fixed by #2108
Assignees

Comments

@davidnikdel-epic
Copy link

davidnikdel-epic commented May 24, 2019

Package + Version

  • @sentry/node

Version:

4.6.6
5.3.0

Description

Some time after 4.1.1 sentry started depending on https-proxy-agent. https-proxy-agent depends on agent-base which does a little nasty thing where it patches over node-core's https.request here

Problems are:

  1. this patch only supports the 2 parameter form.
  2. this patch does not support any forms where a URL object is passed in (instead of the string) due to its reliance on Object.assign

Docs on node's https.request

Unfortunately this means any app that depends on @sentry/node also receives this lovely bug.

@BYK
Copy link
Member

BYK commented Jun 3, 2019

Just hit this today myself. Looks like introduced by 58c9111

I think we can make the import optional based on a proxy being set or not to limit the damage. The ideal solution would be to patch and upgrade agent-base but @TooTallNate doesn't seem to be responding to PRs on the repo. Worst case, we can fork it and use yarn resolution overrides to fix this upstream.

@BYK
Copy link
Member

BYK commented Jun 3, 2019

@BYK
Copy link
Member

BYK commented Jun 4, 2019

Submitted TooTallNate/node-agent-base#27

@jiangfengming
Copy link

Still has problem

require('@sentry/node')
const https = require('https')

const req = https.request('https://www.example.com/', {}, res => {
  console.log(res.statusCode)
})

req.end()

Throws:

events.js:59
    throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
    at checkListener (events.js:59:11)
    at ClientRequest.once (events.js:301:3)
    at new ClientRequest (_http_client.js:176:10)
    at Object.request (https.js:305:10)
    at Object.request (/Users/fenix/projects/tests/node_modules/.registry.npmjs.org/agent-base/4.3.0/node_modules/agent-base/patch-core.js:25:22)
    at Object.<anonymous> (/Users/fenix/projects/tests/https.request.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)

@BYK
Copy link
Member

BYK commented Jun 20, 2019

@jiangfengming this fix has not been released yet, so that's probably why you are still having this issue.

@kamilogorek
Copy link
Contributor

kamilogorek commented Jun 20, 2019

@jiangfengming 5.4.2 with the fix included has been released, give it a try :)

@jiangfengming
Copy link

Upgraded to 5.4.2, still throws. From the error stack, I saw agent-base is v4.3.0.

/Users/fenix/projects/tests/node_modules/.registry.npmjs.org/agent-base/4.3.0/node_modules/agent-base/patch-core.js:25:22

@BYK
Copy link
Member

BYK commented Jun 21, 2019

@jiangfengming can you share the new stack trace for us to investigate please?

@davidnikdel-epic
Copy link
Author

Doesn't appear that the patch TooTallNate/node-agent-base#27 addresses http.request (line 13). Only fixes http.get. http.request also supports a 3 param form as well now according to nodejs docs linked above.

Additionally Object.assign will not copy any properties from a URL object because they are not own-properties so that part is a bug as well.

@jiangfengming
Copy link

@BYK

events.js:59
    throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
    at checkListener (events.js:59:11)
    at ClientRequest.once (events.js:301:3)
    at new ClientRequest (_http_client.js:176:10)
    at Object.request (https.js:305:10)
    at Object.request (/Users/fenix/projects/tests/node_modules/.registry.npmjs.org/agent-base/4.3.0/node_modules/agent-base/patch-core.js:25:22)
    at Object.<anonymous> (/Users/fenix/projects/tests/https.request.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)

@BYK
Copy link
Member

BYK commented Jun 24, 2019

@davidnikdel-epic @jiangfengming - thanks for the responses. My bad confusing the two methods. Will re-open this issue and try to fix it soon!

@kamilogorek
Copy link
Contributor

PR pending TooTallNate/node-agent-base#28

@sanchezjjose
Copy link

Hi we are seeing this issue still. Is there any eta on releasing a possible fix? Specifically seeing new relic external calls breaking, as described here: #2155

@kamilogorek
Copy link
Contributor

Pinged the owner of the node-agent-base repo. If it won't be fixed soon, we'll fork the repo ourselves and/or use different solution.

@BYK
Copy link
Member

BYK commented Sep 13, 2019

@kamilogorek no need to ping the owner as we also have access. I'll try to spend some time on this today and tomorrow.

@kamilogorek
Copy link
Contributor

TIL 🙃

@kunal15595
Copy link

Any progress here?

@jstewmon
Copy link

Now that this issue page is working again, this can be closed since #2355 was merged, right?

@HazAT HazAT closed this as completed Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants