AggregateError in Websocket

avnikk
type: 'error',
message: '',
error: AggregateError [EHOSTUNREACH]:
at internalConnectMultiple (node:net:1139:18)
at afterConnectMultiple (node:net:1712:7) {
code: 'EHOSTUNREACH',
[errors]: [ [Error], [Error] ]
}
}
  • avnikk
    i am trying to connect it, but it keeps getting disconnected after few mins
  • avnikk
    if i send any invalid or null token, or null value to socket will it close the socket??
  • avnikk
    avnikk edited January 14
    please let me know if code needed of execution
  • avnikk
    update : it is still getting disconnected
  • avnikk
    WebSocket error: ErrorEvent {
    10|Zerodha | target: WebSocket {
    10|Zerodha | _events: [Object: null prototype] {
    10|Zerodha | open: [Function],
    10|Zerodha | message: [Function],
    10|Zerodha | error: [Function],
    10|Zerodha | close: [Function]
    10|Zerodha | },
    10|Zerodha | _eventsCount: 4,
    10|Zerodha | _maxListeners: undefined,
    10|Zerodha | readyState: 2,
    10|Zerodha | protocol: '',
    10|Zerodha | _binaryType: 'arraybuffer',
    10|Zerodha | _closeFrameReceived: false,
    10|Zerodha | _closeFrameSent: false,
    10|Zerodha | _closeMessage: '',
    10|Zerodha | _closeTimer: null,
    10|Zerodha | _closeCode: 1006,
    10|Zerodha | _extensions: {},
    10|Zerodha | _receiver: null,
    10|Zerodha | _sender: null,
    10|Zerodha | _socket: null,
    10|Zerodha | _isServer: false,
    10|Zerodha | _redirects: 0,
    10|Zerodha | url: 'wss://ws.kite.trade/?api_key=&access_token=&uid=',
    10|Zerodha | _req: null,
    10|Zerodha | [Symbol(shapeMode)]: false,
    10|Zerodha | [Symbol(kCapture)]: false
    10|Zerodha | },
    10|Zerodha | type: 'error',
    10|Zerodha | message: '',
    10|Zerodha | error: AggregateError [EHOSTUNREACH]:
    10|Zerodha | at internalConnectMultiple (node:net:1139:18)
    10|Zerodha | at afterConnectMultiple (node:net:1712:7) {
    10|Zerodha | code: 'EHOSTUNREACH',
    10|Zerodha | [errors]: [ [Error], [Error] ]
    10|Zerodha | }
    10|Zerodha | }
  • sujith
    Make sure you are not blocking the thread on which you are receiving ticks.
  • avnikk
    would this work?

    function onTicks(data1) {
    try {
    if (!Array.isArray(data1)) return;

    data1.forEach(data => {
    if (!data || data.mode !== 'full') {
    return;
    }
    // Offload the publish operation to a later iteration of the event loop
    setImmediate(() => {
    redisPublisher.publish('DataSender', JSON.stringify(data));
    });
    });
    } catch (error) {
    console.error(`Error processing message: ${error}`);
    }
    }
  • avnikk
    did not work sujith, it is still keeps getting disconnect works for few mins then stops working, keeps diconnecting
  • avnikk
    can u please be quick or connect or call or email, it is causing lot of issue to me any help would be really greatfull

  • sujith
    You shouldn't do anything inside onTicks, offload everything to a secondary thread.

    PS: For testing remove everything there.
  • avnikk
    okay @sujith can u help by second thread do i have to make and pass it to another function or do i need to use worker thread to do so?
  • avnikk
    and @sujith what causes this AggregateError?
  • sujith
    In JavaScript, you need to use async method.
    You can read about AggregateError here.
Sign In or Register to comment.