Socket hang up error

Team

This was originally posted to postman support. They told me to post it in the community.

I am getting socket hang up error while executing the following using newman(4.4.0) after executing few iterations. First few iterations are running fine. After that getting this error. There are no coding issues. The test suite is working fine when executed locally (desktop enterprise version 7.26) for 1-2 iterations.
is there a way to make sendRequest call synchronously or equivalent one to make a synchronous call?

  1. Making a get request returns a response. The response returns items array. One of the attribute in the items array is url. items array’s length is around 100-300. For example items[0].url…items[99].url.
  2. Iterating over the response array till the length of the array
  3. The test (test tab) checks if the url(s) returned is valid or not by using the following code snippet
  4. It is executing fine when executed locally or using postman desktop OR from command line using newman when the array size is small say 10.

Error

**5093. Error socket hang up **
iteration: at request
12 inside “”

Code snippet

//for loop to go through each array item from the response
pm.sendRequest(url, function (err, res) {
if (res.code !==200)
{
console.log("This url is not reachable: " +url);
console.log("Error code = "+res.code);
}
else
{
success = true;
}
});
//end of for loop

I need to verify each url from the response. The tests are failing due to socket hang up error. is there a way to make sendRequest call synchronously?

Appreciate your suggestions/input.

Hi @rjayaram,

Do update your post with the latest information, so that anyone looking at it can provide you with help.

Cheers

Hi Amit

Thanks. I am pasting the latest code here. As you suggested, I have moved the timeout(in milliseconds) parameter to first position. However the values of url and idx are not recognized in the function. It was working before moving the parameter to first position.

Here is the code snippet of calling

//for loop to parse the response and get urls from the result items

console.log("url before calling the function= "+url); //This is printed correctly
 setTimeout(performRequest,11000,url,idx); // Call the function with a delay of 11 seconds
 idx++;

*//end of for loop*
*//end of test*

//Function defined in the same test tab
function performRequest(url,idx) {

   pm.sendRequest(url,function (err, res) {
       console.log('Finsihed: ' + idx); //idx and url values are undefined
       console.log('url = ' + url);
   });
}

Version which worked before, however semantically it seems incorrect
setTimeout(performRequest(url,idx), 11000);

Hey @rjayaram

Try this, it should work as intended:

setTimeout(performRequest.bind(null, url, idx),5000); 

setTimeout(performRequest, 11000, URL, idx); is a newer syntax and looks like not currently available via the NodeJS modules in the Postman Sandbox.