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
Allow a connect timeout to be specified #1739
Comments
Hi @matthiash, The idea is great. What is the current status of this issue and can I help you or the axios team somehow? |
Well, I haven't gotten any feedback on my PR from anyone on the axios team. I solved my problem by using got instead. It allows me to specify timeouts for connect and request separately: https://github.com/sindresorhus/got#timeout |
+1 this is big problem. Work around is to add a CancelToken, but it seems this could easily be baked in to the core.. |
@benb1983 Can you give an example of how to implement that with |
@gwuah something like this... Sorry I lifted it from my code, but hopefully gives you an idea
|
+1 |
+1 |
Hi, I looked at the pull request, I think this is not the way to go about making this change. I will have a look in the future at how we can solve this. For now we are working on a release, after which we will look at this again. Thanks |
@jasonsaayman, any updates on when this issue might be revisited? |
In node you can do this by configuring the agents in the defaults, in an instance, or per request. import axios from "axios";
import http from "http";
import https from "https";
axios.defaults.httpAgent = new http.Agent({ timeout: 5000 });
axios.defaults.httpsAgent = new https.Agent({ timeout: 5000 });
let client = axios.create({
httpAgent: new http.Agent({ timeout: 5000 }),
httpsAgent: new https.Agent({ timeout: 5000 }),
});
let response = axios.request({
httpAgent: new http.Agent({ timeout: 5000 }),
httpsAgent: new https.Agent({ timeout: 5000 }),
}); |
Thanks @tdaniely this workaround with the axios.defaults.timeout = 3000
axios.defaults.httpAgent = new http.Agent({ timeout: 500 })
axios.defaults.httpsAgent = new https.Agent({ timeout: 500 })
axios.get("https://www.google.com:81")
.catch(console.log) // display 'timeout of 3000ms exceeded' but timeout after 500ms |
Yes I was checking the timeout behaviour and I noticed some weird things in the code. |
Thank you @tdaniely this helped me too, I couldn't understand why I wasn't getting a timeout but it is working fine now with your tip. |
same here, we are experiencing ECONNABORTED errors |
See #4209 |
Before Axios V1 you can do: axios.get("https://www.google.com:81", {
httpAgent: http.Agent({ timeout: 500 }),
httpsAgent: https.Agent({ timeout: 500 }),
}); I'm not sure if this works with Axios V1. |
Summary
I want to use axios to connect to an http-server that is available via several different servers with different url:s. If one of the servers does not respond, I want to try another server instead. To get fast failovers, I want to set a low timeout for the request.
But the server sometimes takes a long time to respond (when I am making a complex query). To give the server time to generate the response, I have to set a high timeout.
What I really want to do is set a low connectTimeout, so that if the server has not accepted the tcp connection within this timeout, the request is aborted, but a high timeout to give the server time to generate the response.
Context
PR coming up.
The text was updated successfully, but these errors were encountered: