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
When an idle timeout is triggered the socket will receive a 'timeout' event but the connection will not be severed. The user must manually call socket.end() or socket.destroy() to end the connection.
And since follow-redirects is used as a drop-in replacement for http/https (at least by axios), I'd expect its behavior to follow the same rules.
My use-case is axios of a streaming request. If I activate timeout, even after receiving 200 OK the connection is sometimes aborted during streaming.
Example:
importaxiosfrom'axios';importhttpfrom'http';importThrottlefrom'throttle';importfsfrom'fs';importurlfrom'url';import{Writable}from'stream';constserver=http.createServer((req,res)=>{res.writeHead(200);fs.createReadStream(url.fileURLToPath(import.meta.url)).pipe(newThrottle(32)).pipe(res);});constport=4040;server.listen(port,()=>{console.log(`Server is running on http://localhost:${port}`);});setTimeout(()=>server.close(),2000);classWritableTestextendsWritable{_write(){}}asyncfunctionmain(){constbuffer=newWritableTest();consturl=`http://localhost:${port}/test`;console.log('start');constresponse=awaitaxios(url,{timeout: 20,responseType: 'stream',});console.log(`${response.status}${response.statusText}`);response.data.pipe(newThrottle(300)).pipe(buffer);response.data.on('end',()=>console.log('end'));response.data.on('error',(err)=>console.error('error',err));}main().catch((err)=>console.error(err.message));
Output:
start
Server is running on http://localhost:4040
200 OK
error Error: aborted
at connResetException (node:internal/errors:717:14)
at Socket.socketCloseListener (node:_http_client:462:19)
at Socket.emit (node:events:525:35)
at TCP.<anonymous> (node:net:322:12) {
code: 'ECONNRESET'
}
If I set maxRedirects: 0 then the connection is not aborted.
The text was updated successfully, but these errors were encountered:
I'm not sure. This is a different problem. The internal timers are cleared on response, but socket.setTimeout remains active, and should still report a timeout event, and I don't see that the timeout -> destroy callback is removed on clearTimer.
Hi,
Can you please explain why do you destroy the socket on timeout?
According to the docs of
socket.setTimeout
:And since follow-redirects is used as a drop-in replacement for
http
/https
(at least byaxios
), I'd expect its behavior to follow the same rules.My use-case is axios of a streaming request. If I activate timeout, even after receiving 200 OK the connection is sometimes aborted during streaming.
Example:
Output:
If I set
maxRedirects: 0
then the connection is not aborted.The text was updated successfully, but these errors were encountered: