Requests with timeout still hand indefinitely
See original GitHub issueI 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:
- Created 8 years ago
- Comments:16 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
any update on this issue? I have the same problem in some of the android devices (React Native), Timeout doesn’t happen at all.
@mzabriskie This is still happening at least in React-Native
My request is sent, the result is there before timeout runs out and the .then() is not called if I add the timeout parameter.