# Socket hang up error

**URL:** <https://community.postman.com/t/socket-hang-up-error/13423>\
**Category:** Help Hub\
**Tags:** newman-project, tests, collections\
**Created:** [June 15, 2020, 6:35pm UTC](https://community.postman.com/t/socket-hang-up-error/13423 "2020-06-15T18:35:54Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![amit](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/amit/32/2056_2.png) [@amit](https://community.postman.com/u/amit)\
**Post date:** [August 4, 2020, 3:24am UTC](https://community.postman.com/t/socket-hang-up-error/13423/10 "2020-08-04T03:24:57Z")

</div>

Hey Raje,

I think I understand why things were failing for you.

You mentioned using a `for` loop, which I missed.  
Inside the `for` loop you are calling `setTimeout()` to initiate the `performRequest()` function.

Since `setTimeout` would return back immediately, all your requests would again be called pretty much simultaneously.

You should have something like the following to call your requests, instead of an explicit loop construct.

```
// I've put in some dummy data here
// in your case `requestList` would be the list of URLs you read from the response
let requestList = [
   "http://localhost?id=1",
   "http://localhost?id=2",
   "http://localhost?id=3",
   "http://localhost?id=4",
   "http://localhost?id=5",
   "http://localhost?id=6",
   "http://localhost?id=7",
   "http://localhost?id=8",
   "http://localhost?id=9",
   "http://localhost?id=10",
];

// We are setting a global index variable to keep track of requests being sent
let idx = 0;

// This function will execute the request to the URLs in requestList
function performRequest() {
    
    // URL to send the request to
    let url = requestList[idx];
    console.log("Calling:", url);

    // Send the actual request
    pm.sendRequest(url, (err, res) => {
        console.log("Finished:", requestList[idx]);
        
        // Check if requests are remaining and call the next one after 2 seconds delay.
        if( ++idx < requestList.length) {
            setTimeout(performRequest, 2000);
        } 
    });
}

// Start sending requests
performRequest();

```

~~Unfortunately, `async`-`await` and `promise` aren’t yet supported within Postman sandbox, else we could have a cleaner solution. Till then, the above solution should work!~~

- [https://github.com/postmanlabs/postman-app-support/issues/4131](https://github.com/postmanlabs/postman-app-support/issues/4131)
- [https://github.com/postmanlabs/postman-app-support/issues/5606](https://github.com/postmanlabs/postman-app-support/issues/5606)

Just came to know about a hack to make the async/await work in Postman sandbox, thanks to @kevin.swiber 🙌  
Linking to their solution: [Executing sync requests programmatically from a pre-request or test scripts](https://community.postman.com/t/executing-sync-requests-programmatically-from-a-pre-request-or-test-scripts/14678/2)

---

_[View the full topic](https://community.postman.com/t/socket-hang-up-error/13423)._
