节点中第二次请求延迟15秒

我有一个服务器需要发送多个http请求。 但是除第一个请求之外,每个请求都会触发一个15秒的延迟。

如果我从linux控制台,POSTman或Fiddler发送请求,它的工作很好,没有延迟,但我不能得到它从节点工作。

我已经尝试使用https.get()request ,套接字,甚至在一个单独的文件分叉请求。 但延误还在。 服务器回复正确的Connection: close标题。 该服务器是一个nginx服务器。

从节点工作的唯一时间是如果我把我的请求在一个单独的脚本,只运行这个脚本。 这可能是有效的,因为节点在请求后退出并释放连接。

我曾尝试与agent: false ,我发送Connection: close服务器,但它为什么需要15秒钟closures,为什么不使用小提琴手或POSTMAN时发生这种情况?

编辑:添加代码。 这个代码在我第一次运行的时候运行的非常完美,但是如果我运行了两次或者更多的话,延迟就会出现。 这是导致延迟的第二个函数,第一个函数工作正常。

 async.waterfall([ function(cb) { console.log('making first connection'); var post_data = querystring.stringify({ 'login' : username, 'password' : password }); var options = { hostname: 'hostname', port: 443, path: '/path', method: 'POST', agent: agent, pool: false, keepAlive: false, followRedirect: false, headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': post_data.length } }; // get headers including cookie var req = https.request(options, function(res) { console.log("statusCode: ", res.statusCode); cb(null, res.headers) }); req.write(post_data); req.end(); }, function(header, cb) { console.log('making second connection'); https.request({ host: 'my.server', path: '/' + encodeURIComponent(params), port: 443, method: 'GET', headers: { 'Cookie': 'IFLANG=eng;SESSID=somesession', 'Connection': 'Close', 'Content-Length': 0 } }, function(res) { console.log(res.headers); }).on('error', function(err){ console.log(err); }).end(); }, ], function (err, result) { if(err) console.error(err); callback(err, result); }); 

更新:这段代码会导致相同的延迟,但是当从命令行运行它作为curl命令时,我可以毫不迟延地捶打服务器。

 var args = [ 'https://myserver' + encodeURIComponent( urlPath ), '-k', '-v', '-0', '--no-keepalive', '-b SESSID=someSessionIDfromFirstFunction', ]; child_process.spawn('curl', args);