在节点中发出大量请求时(使用版本6.3.0,但在其他版本上也发生了这种情况),我收到错误getaddrinfo ENOTFOUND.
研究此问题我发现旧版本存在以下github问题节点:https://github.com/nodejs/node-v0.x-archive/issues/5488
但是,我无法在该线程中找到解决方案。
该线程确实提供了以下示例代码:https://gist.github.com/eelcocramer/5626801
要点有三个文件:error-case.js
,fixed-error-case.js
和success-case.js
但是,没有任何文件可以正常工作。
运行error-case.js
会产生以下结果:
...
Request count = 1569
STATUS: 200
Request count = 1570
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 1570
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 1570
...
然而,当我运行fixed-error-case.js
时,我得到以下内容:
...
Request count = 1562
STATUS: 200
Request count = 1563
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 1563
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 1563
...
与success-case.js
Request count = 1563
STATUS: 200
Request count = 1564
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 1564
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 1564
^C
但是,更值得注意的是,如果我再次运行它(等待1分钟后),我会得到以下结果:
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 0
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 0
problem with request: getaddrinfo ENOTFOUND www.google.com www.google.com:80
Last successful request count = 0
因此,有趣的是,错误似乎会持续多次运行。
此外,由于此示例代码并不完全是我实际运行的代码,因此我还应注意,我已尝试将request-promise
与bluebird's map
函数结合使用concurrency
,以便一次只有这么多的承诺是活跃的,但这也没有解决问题。 (尝试运行~300个请求,并发设置为5仍然导致失败)
任何帮助/想法都将不胜感激。
由于