1

I am getting a Socket Hangup error when attempting to connect to an external web site, an example of a failing site given below. The code is working for other sites and I can successfully access the test site if I rewrite the code in Python. I am unable to make changes to the external site so am looking to enhance the NodeJS script to handle the connection. Any help appreciated

let request = require("request-promise");
let needle = require("needle");

//Check if can connect to site

    let arrTestCases = ["https://compassandstars.com"];

    for (x in arrTestCases) {
         chkcon(arrTestCases[x])
    }

    async function chkcon(req) {
        let resultJSON = {};
        let data;
        try {
            console.log ("Validating blog " + req);
    //Attempt using RequestPromise, fails with same error
    //      let getURL = await request({
    //          url: req,
    //          headers: {
    //              'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' 
    //          }
    ////            headers: {
    ////                'User-Agent': 'ouruseragent',
    ////                'Connection': 'keep-alive'
    ////            }
    //      })

            needle('get', req)

             .then(function(response) {
                resultJSON = {ValidURL: true};
                console.log("URL Validated successfully", response.body);
             })
             .catch(function(err) {
                console.log(err);
             })

        } catch (e) {
            console.log("Bad Blog URL ",e.message);
        } finally {
            console.log("Result: " + JSON.stringify(resultJSON), req);

        }

The error response:

Result: {} https://compassandstars.com
{ Error: socket hang up
    at TLSSocket.onConnectEnd (_tls_wrap.js:1073:19)
    at Object.onceWrapper (events.js:219:13)
    at TLSSocket.emit (events.js:132:15)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)
  code: 'ECONNRESET',
  path: null,
  host: 'compassandstars.com',
  port: 443,
  localAddress: undefined }

I can recreate the issue using NodeJS 8.10 on AWS Lambda and locally on my machine using NodeJS 9.6.1.

My research indicates it may be an error finding a compatible cipher to make the SSL connection but I'm unable to find out how to force Request to change the request to handle this.

Daz
  • 71
  • 2
  • 5
  • Socket hang ups on lambda usually indicate lambda timeouts or out of memory – bryan60 Mar 18 '19 at 23:01
  • Hi Bryan, to confirm the Lambda isn't timing out, it has a 60 second timeout and returns fine. The issue can also be recreated locally (i.e. not running via AWS or lambda just executing from my own machine) so isn't specific to AWS/Lambda. – Daz Mar 18 '19 at 23:10
  • Eh. It can indicate an issue on the other side of the connection, but since it’s reliably working in python then it’s definitely something your side. I’ve seen these issues rarely but it’s almost always reaching the limits of lambda/node. Too many simultaneous connections, too much memory being used, things like that. Lambda will cut your connections when you’re about to breach your limits and that’s when you see this error – bryan60 Mar 18 '19 at 23:18
  • Thanks Bryan, appreciate the feedback - in this case I can confirm 100% it is unrelated to Lambda as when executing locally it isn't using Lambda in any way - just straight via node. Also doesn't seem related to number of connections as it is only a single connection and tried over several days and fails 100% of the time. No visible memory issues either. – Daz Mar 18 '19 at 23:41
  • Eh can’t help then. Not familiar with needle. Odd that other requests work reliably in node and this request works reliably in python and then this particular request fails reliably in node. The general gist of this error though is that your request went out but the response couldn’t be received properly for some reason. It’s a poor error message. – bryan60 Mar 19 '19 at 00:17

0 Answers0