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 request with agent, set the request timeout not work, timeout is still
agent timeout.
The code:
'use strict';consthttp=require('http');constport=8000;constAGENT_TIMEOUT=3000;constHTTP_TIMEOUT=5000;constserver=http.createServer((req,res)=>{console.log('never response');}).listen({ port },()=>doRequest());functiondoRequest(){constagent=newhttp.Agent({timeout: AGENT_TIMEOUT});constrequest=http.request({host: 'localhost',
port,
agent,timeout: HTTP_TIMEOUT,// The HTTP_TIMEOUT will not work.},res=>{});request.end();conststart=Date.now();request.on('timeout',()=>{console.log('timeout:'+(Date.now()-start));// It print 3000, not 5000request.abort();server.close();});request.on('error',()=>{});}
I expect request timeout will overwrite the agent time out.
That's a bug for more reasons than one because timeout isn't a documented http.Agent option and shouldn't have worked in the first place. It'd be good to document it and ensure overriding works.
Activity
bnoordhuis commentedon Jun 7, 2018
That's a bug for more reasons than one because
timeoutisn't a documentedhttp.Agentoption and shouldn't have worked in the first place. It'd be good to document it and ensure overriding works.Thanks for the bug report, pull request welcome!
killagu commentedon Jun 7, 2018
I'll make a PR to fix it.
http: fix request with option timeout and agent
http: fix request with option timeout and agent