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.

Requests with timeout still hand indefinitely

See original GitHub issue

I have w project where I make tens of thousands of requests to a backend service, scraping some API. I don’t control the backend. To make the process fast, I post the requests in chunks, in parallel.

Sometimes, though, the backend just hangs indefinitely on a request. For that I’d like to have a timeout and just resend new request. Here is the code that I use for that purpose (I’m using the ES7 async/await functionality):

while(true) {
    try {
        let response = await axios.get(url, {timeout: timeout});
        return response.data;
    } catch (e) {
        if (!silent) {
            console.log(`Exception caught: ${JSON.stringify(e)}`);
        }
    }
}

The problem is, even with the timeout settings some of the requests above hang indefinitely - by average 1 per 3000.

To check if the problem is with my code, or with the library I’ve implemented similar functionality using superagent:

while(true) {
    try {
        let promise = new Promise((resolve, reject) => {
            superagent.get(url).timeout(timeout).end((error, response) => {
                if (error) {
                    reject(error);
                } else {
                    resolve(response);
                }
            })
        });
        let response = await promise;
        return response.body;
    } catch (e) {
        if (!silent) {
            console.log(`Exception caught: ${JSON.stringify(e)}`);
        }
    }
}

And the above code works as expected.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
amithgccommented, Jan 27, 2017

any update on this issue? I have the same problem in some of the android devices (React Native), Timeout doesn’t happen at all.

9reactions
Elyx0commented, Apr 22, 2016

@mzabriskie This is still happening at least in React-Native

axios.post(`/create/`, Qs.stringify(payload),{timeout: 1000})
    .then(json => {}).catch(e => {}).

My request is sent, the result is there before timeout runs out and the .then() is not called if I add the timeout parameter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Is a timeout necessary to prevent `requests.get()` from ...
I've been developing an application, where I need to handle temporarily disconnects on the client (network interface goes down). I initially ...
Read more >
Handling timeout in Axios. Quick and easy - Medium
With that default value, any remote end can keep us waiting for the requested resource for an indefinite period. With limited resources at...
Read more >
Timeouts in Python requests - Datagy
This is true for GET , POST , and PUT requests. While this can prevent unexpected errors, it can result in your request...
Read more >
Requests - Handling Timeouts - Tutorialspoint
Not doing so, can cause to wait on that request indefinitely. We can give timeout to the URL by using the timeout param...
Read more >
Server timeout if 2 devices are used in the same network
I have 2 devices: a computer and a Android smartphone on the same network, if a do like 10 requests on my server...
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