You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
timeout specifies the number of milliseconds before the request times out. If the request takes longer than timeout, the request will be aborted.
I believe it is incorrect in Node.js. Axios calls request.setTimeout()here and it invokes socket.setTimeout() internally. The API document explains as the following:
This means the sockets emit a timeout event when it doesn't send or receive data for a certain time. The request can exceed the specified timeout in the case of a huge request payload or slow network.
This is the reproduction code. The server send payload slowly, and the takes about 10 seconds which is longer than timeout.
importhttpfrom'http';importAxiosfrom'axios';importtimerfrom'timers/promises';(async()=>{constserver=http.createServer((req,res)=>{(async()=>{for(leti=0;i<100;i++){res.write('.');awaittimer.setTimeout(100);}res.end();})();});awaitnewPromise((resolve)=>{server.listen(3000,resolve)});conststartAt=Date.now();constaxios=awaitAxios.get('http://127.0.0.1:3000',{"timeout": 5000});constendAt=Date.now();console.log(`Received ${axios.data.length} bytes in ${endAt-startAt} ms`);server.close();})();
Output:
$ node index.mjsReceived 100 bytes in 10035 ms
Relevant File(s)
No response
The text was updated successfully, but these errors were encountered:
I described GET requests can exceed the timeout. On the other hand, I found POST requests with a big payload throws a timeout error when the request spends over the timeout. This behavior depends on follow-redirects which axios uses internally and it is different from the standard socket.setTimeout(). This difference between GET and POST is unexpected one and I found some issues on the follow-redirects repository.
Section/Content To Improve
The
timeout
property in Request ConfigSuggested Improvement
The description of the
timeout
property says:I believe it is incorrect in Node.js. Axios calls
request.setTimeout()
here and it invokessocket.setTimeout()
internally. The API document explains as the following:This means the sockets emit a
timeout
event when it doesn't send or receive data for a certain time. The request can exceed the specifiedtimeout
in the case of a huge request payload or slow network.This is the reproduction code. The server send payload slowly, and the takes about 10 seconds which is longer than
timeout
.Output:
Relevant File(s)
No response
The text was updated successfully, but these errors were encountered: