-
-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requests with timeout still hand indefinitely #124
Comments
I did some digging in the code, and from what I see is that axios is handling request timeout by issuing the req.abort() function (https://github.com/mzabriskie/axios/blob/master/lib/adapters/http.js#L92): // Handle request timeout
req.setTimeout(config.timeout, function () {
req.abort();
}); While superagent is doing a bit more (https://github.com/visionmedia/superagent/blob/5a320d7d3222935718bfde91cae91ade4b371826/lib/node/index.js#L833): if (timeout && !this._timer) {
debug('timeout %sms %s %s', timeout, this.method, this.url);
this._timer = setTimeout(function(){
var err = new Error('timeout of ' + timeout + 'ms exceeded');
err.timeout = timeout;
err.code = 'ECONNABORTED';
self.abort();
self.callback(err);
}, timeout);
} Both aborting the request and fulfilling the callback at the same time. |
IIRC aborting the request should put it into the on error handler. I'll check again to verify. |
This is also happening for me. |
@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. |
any update on this issue? I have the same problem in some of the android devices (React Native), Timeout doesn't happen at all. |
@amithgc still having this issue. running on android too(emulator) |
This workaround works (for React-Native): |
the same is happening for me... after a bunch of request... one will hang forever... :( ... using nodejs |
happening to me too, using React Native 0.52 for Android |
happens in nodejs as well. Why is this issue closed @mzabriskie ? |
ok actually issue is not the timeout I think. Simply try to do couple of hundreds of requests in a loop. It will hang after few. |
Hm. I tried with 1000 requests and it didn't trip it up for me. 😞 |
Using the following code -- which overly verbose in error handling -- I'd expect there be no way to not get a message to stdout from the Axios get call but indeed at random intervals it fails and just hangs. I rerun from where I left off and the endpoint which failed almost always works only to have it fail randomly somewhere else. I would strongly support this being a real issue. try {
content = await axios.create().get<string>(url, {timeout: 5000});
console.log(chalk.grey('- axios content returned from endpoint'));
if(content.status !== 200) {
console.log(chalk.red(`- Returned status from ${url} was ${chalk.bold.yellow(String(content.status))}}`));
problemsCaching.push(business);
return business;
}
if(!content.data) {
console.log(chalk.red(`- Axios responded correctly but payload is empty (${url})`));
problemsCaching.push(business);
return business;
}
} catch (e) {
console.log(chalk.red(`- Problems loading "${url}" for ${business.name}`));
problemsCaching.push(business);
return business;
} |
It's still an issue in 2020. |
I'm seeing this too. Here's my sample code which I'm running on serverless: import axios from 'axios';
class MyHandler {
constructor(event, context, callback) {
this.callback = callback;
}
async myFunction() {
const apiClient = axios.create();
await apiClient.get('', {
baseURL: 'http://www.keyboardsmash-woeuroweuoweuowiueoreureor.com',
timeout: 24000,
}).catch((exception) => {
console.log(`Saw exception ${exception}`);
});
this.callback(null, {});
}
}
export const handle = (event, context, callback) => {
new MyHandler(event, context, callback).myFunction();
}; If I invoke the code from the command line with
and then hang for about 23 seconds before returning control back to the shell. If I hack a |
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):
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:
And the above code works as expected.
The text was updated successfully, but these errors were encountered: