I've run in to an issue with an intermittent failure "Error: socket hang up" when performing an http GET call. The problem seems to be related to the version of follow-redirects, which is a dependency of node-rest-client.
Here is a sample bit of code calling a public endpoint api (so will be replicable for anyone):
I ran this script using node in the powershell => node test.js
test.js
const Client = require('node-rest-client').Client;
let endpoint = "https://apipheny.io/free-api/";
let query = `${endpoint}`;
let args = __configArguments('text/plain');
for (let i = 0; i < 50; i++) {
try {
let req = (new Client()).get(query, args, (data) => {
console.log('test\n')
console.log(data)
});
req.on('error', (err) => {
console.log('test1\n')
console.log('Error', err)
});
} catch (error) {
console.log('test2\n')
console.log('Exception', error)
}
}
function __configArguments(contentType) {
return {
headers: {
'Content-Type': contentType,
},
requestConfig: {
'timeout': 1000,
'noDelay': true,
'keepAlive': true,
'keepAliveDelay': 1000
},
responseConfig: {
'timeout': 1000
}
};
}
As I mentioned earlier this seems to be caused by the version of follow-redirects, a dependency of node-rest-client. If I manually install follow-redirects version 1.13.3, we don't get this "Error Error: socket hang up". Anything later than that we start to see this issue.
Would anyone have an inkling to what is going on here, or any potential solutions?
Hello
I've run in to an issue with an intermittent failure "Error: socket hang up" when performing an http GET call. The problem seems to be related to the version of follow-redirects, which is a dependency of node-rest-client.
Here is a sample bit of code calling a public endpoint api (so will be replicable for anyone): I ran this script using node in the powershell => node test.js
test.js
an excerpt of the output is like this
As I mentioned earlier this seems to be caused by the version of follow-redirects, a dependency of node-rest-client. If I manually install follow-redirects version 1.13.3, we don't get this "Error Error: socket hang up". Anything later than that we start to see this issue.
Would anyone have an inkling to what is going on here, or any potential solutions?
Thank you kindly.