KiteTicker how to stop process from carshing

stripathix
stripathix edited March 2022 in Node JS client
I have a KiteTicker with auto-reconnect enabled like
const ticker = new KiteTicker({
api_key,
access_token,
});
ticker.autoReconnect(true, 3, 5);
ticker.connect();
ticker.on('connect', () => {
console.log('TICKER CONNECTED');
});
It works but when maxRetry is reached it just crashes my node service because there is a Process.exit(1) in KiteTicker code here:

https://github.com/zerodha/kiteconnectjs/blob/master/lib/ticker.js#L642



Is there any better way to handle this close connection so if it fails on all retry it does not crash nodeService as a whole? Maybe somehow if I can stop it from Reconnect again if MaxRetries - 1 are done?

I tried using something like this but id didn't stopped ticker from reconnecting and eventually crashing app.
 ticker.on('close', (ws, code, reason) => {
if (attemptsMade === MAX_TICKER_RETRY - 1) {
ticker.disconnect();
}
});
  • SRIJAN
    SRIJAN edited March 2022
    Just redefine this attempt reconnection function,remove this process.exit(1) command,and write ticker.disconnect() in that place.
  • stripathix
    How to redefine it? Looks like it is a private method of KiteTicker. Do you mean fork it and overwrite it?
  • SRIJAN
    I don't know NodeJS ,so you have to figure it out yourself or somebody might help you on this forum.
  • stripathix
    Thanks, @SRIJAN :) I will try it out.
  • rakeshr
    rakeshr edited March 2022
    @stripathix
    Is there any better way to handle this close connection so if it fails on all retry it does not crash nodeService as a whole?
    Not able to get you on this. Do you want to keep the WebSocket connection active? After exhausting all retry attempts.
    But, if you want to keep the websocket connection active, you can increase the max_retry or else let the websocket close.
  • stripathix
    @rakeshr no what I was thinking is that when all retries are exhausted it does not crash the whole node service and there can be a callback where I can decide what to do next like I can notify on slack that ticker is failing after all retries. Also, that will make sure that all other code that does not use Ticker can still work like REST_API only ticker fails.
  • sujith
    @stripathix,
    In a general scenario, client shouldn't get disconnected so many times. If it is disconnecting 50 or 100 times then there is some issue.

    If you wish to get the event after maximum reconnect count then you can fork kiteconnectjs and do it at your end. You need to modify here.
  • stripathix
    @sujith , thanks for sharing
  • teknas
    teknas edited October 2023
    <pre class="CodeBlock"><code>
    ticker.on('reconnect', function (reconnect_count, reconnect_interval) {
    console.log('Reconnecting: attempt - ', reconnect_count, ' interval - ', reconnect_interval)
    if (reconnect_count > MAX_ATTEMPTS - 2) {
    ticker.autoReconnect(false)
    }
    })

    This worked for me
Sign In or Register to comment.