Describe the bug
We've been hunting down multiple weird bugs recently, all of them related to outgoing HTTP requests. After some trial-and-error I found it's most likely caused by APM's instrumentation as disabling it fixed all issues.
Example of our code:
got('https://registry.npmjs.org/uikit').then((response) => {
console.log(JSON.parse(response.body));
});
This sometimes throws an error:
Unexpected token � in JSON at position 0 in "https://registry.npmjs.org/uikit":
�����T�n�6������MQw=�h�h��/���H����\K�JR��E���d;N��h����I<�3�������@
The response, which looks completely broken at first, is actually correct, except it's gzipped - npm responds with content-encoding: gzip header and the got module is supposed to gunzip the response and pass the result to our callback. For some reason, sometimes it passes the raw response instead.
At first I suspected this was an issue with got, so I tried downgrading to an older version which we've been using for a while without any problems but that didn't help. Then I tried to disable instrumentation and as I already said, that fixed all issues. I went through the code of this module but didn't find any got-specific code, so I'm not sure if this only affects that module or all outgoing requests.
Unfortunately, I was not able to reliably reproduce this locally. In production, we get the error roughly for one in a hundred requests and usually when a request for the same URL is made a few seconds later, it succeeds. It is also not specific to the host being npmjs.org or response format being json - we fetch data and files from multiple different services and it affects all of them.
Let me know if there's anything I can do to get this problem identified and fixed.
Environment (please complete the following information)
- OS: Linux
- Node.js version: 8.11.3
- APM Server version: 6.3.0
- Agent version: 1.8.1
How are you starting the agent? (please tick one of the boxes)
Additional context
Add any other context about the problem here.
Describe the bug
We've been hunting down multiple weird bugs recently, all of them related to outgoing HTTP requests. After some trial-and-error I found it's most likely caused by APM's instrumentation as disabling it fixed all issues.
Example of our code:
This sometimes throws an error:
The response, which looks completely broken at first, is actually correct, except it's gzipped - npm responds with
content-encoding: gzipheader and the got module is supposed to gunzip the response and pass the result to our callback. For some reason, sometimes it passes the raw response instead.At first I suspected this was an issue with got, so I tried downgrading to an older version which we've been using for a while without any problems but that didn't help. Then I tried to disable instrumentation and as I already said, that fixed all issues. I went through the code of this module but didn't find any got-specific code, so I'm not sure if this only affects that module or all outgoing requests.
Unfortunately, I was not able to reliably reproduce this locally. In production, we get the error roughly for one in a hundred requests and usually when a request for the same URL is made a few seconds later, it succeeds. It is also not specific to the host being
npmjs.orgor response format beingjson- we fetch data and files from multiple different services and it affects all of them.Let me know if there's anything I can do to get this problem identified and fixed.
Environment (please complete the following information)
How are you starting the agent? (please tick one of the boxes)
agent.start()directly (e.g.require('elastic-apm-node').start(...))elastic-apm-node/startfrom within the source code-r elastic-apm-node/startAdditional context
Add any other context about the problem here.
Agent config options
Click to expand
package.jsondependencies:Click to expand