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.

"Error: socket hang up" when using node-rest-client if follow-redirects Ver > 1.13.3

See original GitHub issue

Hello

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:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
RubenVerborghcommented, Jul 4, 2022

Super, thanks!

0reactions
RubenVerborghcommented, Sep 25, 2022

@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.

why it’s not a problem with versions of follow-redirects <= v.1.13.3

That might be cdd921f16a76002e9be2f9124bbf89d7133ccb46; i.e., you just didn’t reach the timeout.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS - What does "socket hang up" actually mean?
There are two cases when socket hang up gets thrown: When you are a client. When you, as a client, send a request...
Read more >
Issues · aacerox/node-rest-client - GitHub
"Error: socket hang up" when using node-rest-client if follow-redirects Ver > 1.13.3 ... HTTPS: unable to verify the first certificate error. #206 opened...
Read more >
NodeJS - What does socket hang up actually mean - Edureka
This error is caused by the end of your socket. You should catch this error and decide what to do with it, such...
Read more >
Hang in There! (A solution to socket hang up) - Medium
This blog post will go over my process of solving the error and what the actual (and surprisingly/annoyingly) simple solution was. First thing ......
Read more >
Could not get any response socket hang up - Help - Postman
I am not able to Post to the server. I am receiving “Could not get any response” error. While checking the logs found...
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