question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaking expected Node behaviour for http.get

See original GitHub issue

Related: https://github.com/nock/nock/pull/1588 and https://github.com/newrelic/node-newrelic/issues/316

New Relic (https://github.com/newrelic/node-newrelic) is overwriting http.get and http.request like you do in https://github.com/mastermatt/nock/blob/master/lib/common.js#L102. But when http.get is calling http.request like here, a call to http.get will call http.request twice when using nock in a New Relic test.

To prove that this is not native Node behaviour (at least on Node 12):

const http = require('http');

function request() {
  console.log('http.request', arguments);
}

http.request = request;

// our request function is not called
http.get('http://google.com', () => {});

Looks like this change in https://github.com/mastermatt/nock/blob/3fbc69d74f6d23b33c2c6b144aa9fbf1d855cd18/lib/common.js#L102-L104 works:

const req = newRequest(proto, overriddenGet.bind(module), [
  input,
  options,
  callback,
])
req.end()
return req

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
paulmelnikowcommented, Feb 6, 2020

I’ve opened #1868 with two new tests.

0reactions
nockbotcommented, Feb 10, 2020

🎉 This issue has been resolved in version 11.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP/1 request destroy behavior change on framing error
In Node.js 8 and below, the request object would be destroyed and be left in non-readable state (i.e. req.readable === false ).
Read more >
Add Retries to HTTP requests - DEV Community ‍ ‍
Whether you're making API calls from Node.js or in the browser, connection failures are going to happen eventually. Some request errors are ...
Read more >
node.js - nodejs - first argument must be a string or Buffer
As the error message says, write expects a string or Buffer object, so you must ... request({ uri: 'http://www.google.com', method: 'GET', ...
Read more >
HTTP | Node.js v19.3.0 Documentation
maxSockets <number> Maximum number of sockets to allow per host. If the same host opens multiple concurrent connections, each request will use new...
Read more >
How To Create a Web Server in Node.js with the HTTP Module
This function is meant to handle an incoming HTTP request and return an HTTP response. This function must have two arguments, a request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found