【问题标题】:can't resolve getaddrinfo EAI_AGAIN error无法解决 getaddrinfo EAI_AGAIN 错误
【发布时间】:2022-01-25 22:52:48
【问题描述】:

我在运行我的 NodeJS 应用程序 20 分钟后出现此错误,此后一直出现.. 它托管在 AWS (EC2) 我搜索 getaddrinfo EAI_AGAIN 错误,这可能是由 DNS 问题引起的,但我有不知道怎么解决。

WebSocket error: [object Object]
ErrorEvent {
  target:
   WebSocket {
     _events:
      [Object: null prototype] {
        message: [Function: incoming],
        disconnect: [Function],
        close: [Function: close],
        error: [Function] },
     _eventsCount: 4,
     _maxListeners: undefined,
     _binaryType: 'nodebuffer',
     _closeCode: 1006,
     _closeFrameReceived: false,
     _closeFrameSent: false,
     _closeMessage: '',
     _closeTimer: null,
     _extensions: {},
     _protocol: '',
     _readyState: 2,
     _receiver: null,
     _sender: null,
     _socket: null,
     _bufferedAmount: 0,
     _isServer: false,
     _redirects: 0,
     _url: 'wss://stream.binance.com:9443/ws/!bookTicker',
     _req: null },
  type: 'error',
  message:
   'getaddrinfo EAI_AGAIN stream.binance.com stream.binance.com:9443',
  error:
   { Error: getaddrinfo EAI_AGAIN stream.binance.com stream.binance.com:9443
       at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
     errno: 'EAI_AGAIN',
     code: 'EAI_AGAIN',
     syscall: 'getaddrinfo',
     hostname: 'stream.binance.com',
     host: 'stream.binance.com',
     port: '9443' } }

【问题讨论】:

    标签: javascript node.js websocket binance


    【解决方案1】:

    对于以后的读者来说,这个问题是因为 Binance 的 web socket 服务器要求在 10 分钟内响应一个 ping 帧,否则连接将被断开,所以我得到 1006 错误,我用一个 pong 帧修复了这个问题,比如这个:ws.pong(); 否则你会得到一个 1008 错误代码。

    例子:

    const ws = new WebSocket('wss://stream.binance.com:9443/ws/!bookTicker');
    ws.onopen = function(message) {
        console.log("Connected:   ");
        ws.pong();
    }
    ws.on("ping", function(message) {
        ws.pong();
    }); 
    

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 2019-04-23
      • 1970-01-01
      • 2020-05-10
      • 2020-06-12
      • 1970-01-01
      • 2018-04-15
      相关资源
      最近更新 更多