为什么我在Node.js中从10个外部http请求中得到8个响应

为什么我在Node.js中从10个外部http请求中得到8个响应,node.js,request,response,Node.js,Request,Response,My Node.js应用程序在将处理后的信息发送回客户端之前,会在服务器端发出两种类型的http请求: 第一种类型的服务器端请求获取从外部API获取的链接列表(仅1个请求) 第二种类型的服务器端请求获取网页的html(重复10次,因为API返回的列表包含10个URL) 即使我看到请求了10个URL,也只生成了8个响应。代码如下: app.get('/search',函数(clientReq,clientRes){ log(clientReq.query.r); //检索包含10个URL的js

My Node.js应用程序在将处理后的信息发送回客户端之前,会在服务器端发出两种类型的http请求:

  • 第一种类型的服务器端请求获取从外部API获取的链接列表(仅1个请求)
  • 第二种类型的服务器端请求获取网页的html(重复10次,因为API返回的列表包含10个URL)
即使我看到请求了10个URL,也只生成了8个响应。代码如下:

app.get('/search',函数(clientReq,clientRes){
log(clientReq.query.r);
//检索包含10个URL的json数据的第一种请求
var searchReq=https.request({host:'myhost.com',路径:'/?q='+clientReq.query.r},函数(searchRes){
log('search…');
var searchOutput='';
var通信=[];
var=0;
searchRes.on('data',函数(d){
搜索输出+=d;
});
searchRes.on('end',function()){
var obj=JSON.parse(searchOutput);
对于(变量i=0;ivar$=cheerio.load(htmlOutput.toString().substring(htmlOutput.toString().indexOf)(“注意:
等待--
complete()
并不总是被调用。即使请求失败,也应该始终处理未解决的差异。在某个时刻,web服务器(或TCP线路上的某个东西)应该响应(即使它是“连接已关闭”),但可能不是200或预期的数据。10到单个主机的同时连接可能会被HTTPS代理程序阻塞,该代理程序会限制其一次愿意建立的连接数。您可以通过检查
HTTPS.globalAgent.maxSockets
HTTPS.globalAgent.sock来更有效地调试此问题ets
https.globalAgent.requests
以及通过引用
https.globalAgent.maxSockets
设置为
5
(默认值),这是问题的根源。但是,我不明白为什么我成功地获得了8个响应。更奇怪的是,我必须将该值设置为至少
9
,才能获得所有10个响应。我有一个解决方案,但我想了解。
fetchReq ended
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response
starting to read the fetch response
this is the end of the fetch response