admin管理员组

文章数量:1406913

I'm having this error after 20 min of running my NodeJS app, and it's keeps appearing after that.. it's hosted at AWS (EC2) I searched for getaddrinfo EAI_AGAIN errors, it's probably caused by DNS issue, but i have no idea how to solve it.

WebSocket error: [object Object]
ErrorEvent {
  target:
   WebSocket {
     _events:
      [Object: null prototype] {
        message: [Function: ining],
        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:9443/ws/!bookTicker',
     _req: null },
  type: 'error',
  message:
   'getaddrinfo EAI_AGAIN stream.binance stream.binance:9443',
  error:
   { Error: getaddrinfo EAI_AGAIN stream.binance stream.binance:9443
       at GetAddrInfoReqWrap.onlookup [as onplete] (dns.js:56:26)
     errno: 'EAI_AGAIN',
     code: 'EAI_AGAIN',
     syscall: 'getaddrinfo',
     hostname: 'stream.binance',
     host: 'stream.binance',
     port: '9443' } }

I'm having this error after 20 min of running my NodeJS app, and it's keeps appearing after that.. it's hosted at AWS (EC2) I searched for getaddrinfo EAI_AGAIN errors, it's probably caused by DNS issue, but i have no idea how to solve it.

WebSocket error: [object Object]
ErrorEvent {
  target:
   WebSocket {
     _events:
      [Object: null prototype] {
        message: [Function: ining],
        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.:9443/ws/!bookTicker',
     _req: null },
  type: 'error',
  message:
   'getaddrinfo EAI_AGAIN stream.binance. stream.binance.:9443',
  error:
   { Error: getaddrinfo EAI_AGAIN stream.binance. stream.binance.:9443
       at GetAddrInfoReqWrap.onlookup [as onplete] (dns.js:56:26)
     errno: 'EAI_AGAIN',
     code: 'EAI_AGAIN',
     syscall: 'getaddrinfo',
     hostname: 'stream.binance.',
     host: 'stream.binance.',
     port: '9443' } }
Share asked Jan 20, 2022 at 12:57 ALAEDDINALAEDDIN 2811 gold badge3 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

For future readers, the problem is caused because the Binance's web socket server requires to respond to a ping frame within 10 minutes or the connection will be disconnected, so I get the 1006 error, I fixed this issue with a pong frame like this: ws.pong(); otherwise you will get a 1008 error code.

Example:

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

本文标签: javascriptcan39t resolve getaddrinfo EAIAGAIN errorStack Overflow