"Error: socket hang up" when using node-rest-client if follow-redirects Ver > 1.13.3
See original GitHub issueHello
I’ve run in to an issue with an intermittent failure “Error: socket hang up” when performing an http GET call using “node-rest-client”, and the root of 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 to give you an idea of what I’m talking about (Note - I have redacted certain parts with “*******”): I ran this script using node in the powershell => node test.js
test.js
const Client = require('node-rest-client').Client;
let identityServer = 'https://identity.******-********.******.com/identity'
let token_validation_endpoint = identityServer + '/********/accesstokenvalidation';
let accessToken = '**********************';
let query = `${token_validation_endpoint}?token=${accessToken.substr(-32)}`;
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
}
};
}
an excerpt of the output is like this
output
test1
Error Error: socket hang up
at connResetException (internal/errors.js:628:14)
at TLSSocket.socketCloseListener (_http_client.js:449:25)
at TLSSocket.emit (events.js:412:35)
at net.js:675:12
at TCP.done (_tls_wrap.js:563:7) {
code: 'ECONNRESET',
request: ClientRequest {
_events: [Object: null prototype] { error: [Function (anonymous)] },
_eventsCount: 1,
_maxListeners: undefined,
href: 'https://identity.********.**********.*****/identity/*******/accesstokenvalidation?token=*********************',
options: {
host: 'identity.********.**********.*****',
port: null,
path: '/identity/*******/accesstokenvalidation?token=*********************',
href: 'https://identity.********.**********.*****/identity/*******/accesstokenvalidation?token=*********************',
method: 'GET',
headers: [Object]
},
_httpRequest: Writable {
_writableState: [WritableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: [ClientRequest],
_currentUrl: 'https://identity.********.**********.*****/identity/*******/accesstokenvalidation?token=*********************',
_timeout: null,
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false
}
}
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.
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top GitHub Comments
Super, thanks!
@eddiebateson Thanks for the update. I will close this for now until we have a piece of code that reproduces it with only
follow-redirects
.That might be cdd921f16a76002e9be2f9124bbf89d7133ccb46; i.e., you just didn’t reach the timeout.