- Version: v10.15.1
- Platform: Darwin Skadi.local 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64
- Subsystem: http
I've encountered a strange behavior while using Agent Keep-Alive, and I'm not sure it is correct.
I've created a code example to show what I've discovered, pay attention to the configurations of the agents.
'use strict'consthttp=require('http')constagentFalse=newhttp.Agent({keepAlive: false,keepAliveMsecs: 1000,maxSockets: 256,maxFreeSockets: 256})constagentFalseInf=newhttp.Agent({keepAlive: false,keepAliveMsecs: 1000,maxSockets: Infinity,maxFreeSockets: 256})constagentTrue=newhttp.Agent({keepAlive: true,keepAliveMsecs: 1000,maxSockets: 256,maxFreeSockets: 256})constserver=http.createServer((req,res)=>{console.log(req.url,req.headers)res.end('ok')})server.listen(3000,()=>{http.request({port: 3000,path: '/false',agent: agentFalse}).on('error',console.log).end()http.request({port: 3000,path: '/falseInf',agent: agentFalseInf}).on('error',console.log).end()http.request({port: 3000,path: '/true',agent: agentTrue}).on('error',console.log).end()})And this is the log:
/false { host: 'localhost:3000', connection: 'keep-alive' }
/falseInf { host: 'localhost:3000', connection: 'close' }
/true { host: 'localhost:3000', connection: 'keep-alive' }
If this is the expected behavior, can you explain why it works like so?
I've encountered a strange behavior while using Agent Keep-Alive, and I'm not sure it is correct.
I've created a code example to show what I've discovered, pay attention to the configurations of the agents.
And this is the log:
If this is the expected behavior, can you explain why it works like so?