Tho*_*ggi 83 javascript dns error-handling node.js shopify
我的服务器今天扔了这个,这是我以前从未见过的nodejs错误.
Error: getaddrinfo EAI_AGAIN my-store.myshopify.com:443
    at Object.exports._errnoException (util.js:870:11)
    at errnoException (dns.js:32:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)
我想知道这是否与今天影响Shopify和许多其他服务的DynDns DDOS攻击有关.这是一篇关于此的文章.
我的主要问题是做dns.js什么?节点的哪个部分是它的一部分?我可以使用其他域重新创建此错误吗?
xer*_*erq 82
EAI_AGAIN是DNS查找超时错误,表示它是网络连接错误或代理相关错误.
我的主要问题是dns.js做了什么?
更多信息:http: //www.codingdefined.com/2015/06/nodejs-error-errno-eaiagain.html
bas*_*ien 56
如果您使用Firebase Cloud Functions遇到此错误,则是由于免费套餐的限制(仅允许Google服务使用出站网络)。
升级到Flame或Blaze计划即可使用。
Mar*_*nde 28
对于那些每天执行数千或数百万个请求并需要解决此问题的人:
getaddrinfo EAI_AGAIN在服务器上执行大量请求时出现错误是很正常的。Node.js 本身不执行任何 DNS 缓存,它委托与操作系统相关的所有 DNS 事务。
您需要记住,每个 http/https 请求都会执行 DNS 查找,这可能会变得相当昂贵,为了避免这种瓶颈和getaddrinfo错误,您可以实现 DNS 缓存。
http.request(和 https)接受lookup默认为的属性dns.lookup()
http.get('http://example.com', { lookup: yourLookupImplementation }, response => {
    // do something here with response
});
我强烈建议使用已经测试过的模块,而不是自己编写 DNS 缓存,因为您必须正确处理 TTL,以避免难以跟踪的错误。
我个人使用的cacheable-lookup是哪个got(参见dnsCache选项)。
您可以根据特定要求使用它
const http = require('http');
const CacheableLookup = require('cacheable-lookup');
const cacheable = new CacheableLookup();
http.get('http://example.com', {lookup: cacheable.lookup}, response => {
    // Handle the response here
});
或全球范围内
const http = require('http');
const https = require('https');
const CacheableLookup = require('cacheable-lookup');
const cacheable = new CacheableLookup();
cacheable.install(http.globalAgent);
cacheable.install(https.globalAgent);
注意:请记住,如果请求不是通过 Node.jshttp/https模块执行,则.install在全局代理上使用不会对所述请求产生任何影响,例如使用undici
如果您正在使用,undici则可以使用undici.setGlobalDispatcher()
import { Agent, setGlobalDispatcher } from 'undici';
import CacheableLookup from 'cacheable-lookup';
const cacheable = new CacheableLookup();
const agent = new Agent({
    connect: {
        lookup: cacheable.lookup
    }
});
setGlobalDispatcher(agent);
await fetch('https://google.com'); // will be cached
如果您不想为所有请求设置它,您可以执行以下操作:
await fetch('https://google.com', {
    dispatcher: agent
});
Die*_*ner 18
如果您从 docker 容器内收到此错误,例如在npm installalpine 容器内运行时,原因可能是自容器启动以来网络发生了变化。
要解决这个问题,只需停止并重新启动容器
docker-compose down
docker-compose up
来源:https : //github.com/moby/moby/issues/32106#issuecomment-578725551
正如xerq 的出色回答所解释的那样,这是一个 DNS 超时问题。
我想为那些使用适用于 Linux 的 Windows 子系统的人提供另一个可能的答案- 在某些情况下,在 Windows 从睡眠状态恢复后,客户端操作系统中的某些内容似乎有些歪斜。重新启动主机操作系统将解决这些问题(它也可能重新启动 WSL 服务会做同样的事情)。
我在 docker-compose 上遇到了这个问题。结果我忘记将自定义隔离命名网络添加到我的服务中,但无法找到该网络。
太长了;确保在您的撰写文件中,在需要相互通信的两个服务上定义了自定义网络。
我的错误看起来像这样:Error: getaddrinfo EAI_AGAIN minio-service。minio-service当使用主机名调用时,错误来自我的服务器后端minio-service。这告诉我minio-service正在运行的服务无法通过我server正在运行的服务访问。我能够解决此问题的方法是我将 docker-compose 中的 minio-service 更改为:
version: "3.8"
# ...
services:
  server:
    # ...
    networks:
      my-network:
    # ...
  minio-service:
    # ... (missing networks: section)
# ...
networks:
  my-network:
要包含我的自定义隔离命名网络,如下所示:
version: "3.8"
# ...
services:
  server:
    # ...
    networks:
      my-network:
    # ...
  minio-service:
    # ...   
    networks:
      my-network:
    # ...
# ...
networks:
  my-network:
有关 docker-compose 网络的更多详细信息可以在此处找到。
OP 的错误指定了一个主机 ( my-store.myshopify.com)。我遇到的错误在所有方面都是相同的,只是没有指定域。
我的解决方案可能会帮助那些被标题“错误:getaddrinfo EAI_AGAIN”吸引到这里的其他人
我在尝试从最初开发代码的不同虚拟机提供 NodeJs 和 VueJs 应用程序时遇到了错误。
文件vue.config.js读取:
 module.exports = {
   devServer: {
     host: 'tstvm01',
     port: 3030,
   },
 };
当在原始机器上使用时,启动输出为:
App running at:
- Local:   http://tstvm01:3030/ 
- Network: http://tstvm01:3030/
在虚拟机上使用相同的设置tstvm07给我带来了与OP描述的错误非常相似的错误:
 INFO  Starting development server...
 10% building modules 1/1 modules 0 activeevents.js:183                              
      throw er; // Unhandled 'error' event
      ^
Error: getaddrinfo EAI_AGAIN
    at Object._errnoException (util.js:1022:11)
    at errnoException (dns.js:55:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
如果还不是很明显,请改为vue.config.js阅读...
 module.exports = {
   devServer: {
     host: 'tstvm07',
     port: 3030,
   },
 };
...解决了问题。
| 归档时间: | 
 | 
| 查看次数: | 99804 次 | 
| 最近记录: |