429 too many request for websocket connection

iamshaurya
Hi

Today (10th June 2024) after 14:11 i started receiving
```
2024-06-10 14:11:05.472 ERROR 7637 --- [Timer-173] c.s.i.t.service.LiveTickerServiceImpl : Kite connect exception {}

com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.1 429 Too Many Requests
at com.neovisionaries.ws.client.HandshakeReader.validateStatusLine(HandshakeReader.java:232) ~[kiteconnect.jar!/:1.11]
at com.neovisionaries.ws.client.HandshakeReader.readHandshake(HandshakeReader.java:54) ~[kiteconnect.jar!/:1.11]
at com.neovisionaries.ws.client.WebSocket.readHandshake(WebSocket.java:3244) ~[kiteconnect.jar!/:1.11]
at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:3123) ~[kiteconnect.jar!/:1.11]
at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2155) ~[kiteconnect.jar!/:1.11]
at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:214) [kiteconnect.jar!/:1.11]
at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:648) [kiteconnect.jar!/:1.11]
at com.zerodhatech.ticker.KiteTicker.doReconnect(KiteTicker.java:128) [kiteconnect.jar!/:1.11]
at com.zerodhatech.ticker.KiteTicker$1.run(KiteTicker.java:105) [kiteconnect.jar!/:1.11]
at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_362]
at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_362]
```

And didnt receive any tick data after that.

@sujith can you please with this
  • iamshaurya
    I am following https://github.com/zerodha/javakiteconnect to define onConnected, setOnDisconnectedListener, setOnErrorListener methods


    public void onConnected() {
    /**
    * Subscribe ticks for token. By default, all tokens are
    * subscribed for modeQuote.
    */
    log.info("Live ticker connected");
    tickerProvider.subscribe(tradeTokens);
    tickerProvider.setMode(tradeTokens, KiteTicker.modeFull);
    }
    });




    tickerProvider.setOnDisconnectedListener(new OnDisconnect() {
    @Override
    public void onDisconnected() {
    log.error("Live ticker disconnected");
    }
    });

    tickerProvider.setOnErrorListener(new OnError() {
    @Override
    public void onError(Exception exception) {
    // handle here.
    log.error("Kite connect exception {}", exception);
    }

    @Override
    public void onError(KiteException kiteException) {
    // handle here.
    log.error("Kite connect kite exception {}", kiteException);
    }

    @Override
    public void onError(String s) {
    log.error("Kite connect string exception {}", s);
    }
    });

    tickerProvider.setTryReconnection(true);
    // maximum retries and should be greater than 0
    tickerProvider.setMaximumRetries(5000);
    // set maximum retry interval in seconds
    tickerProvider.setMaximumRetryInterval(30);

    /**
    * connects to com.zerodhatech.com.zerodhatech.ticker server for getting
    * live quotes
    */
    tickerProvider.connect();


    In todays log i found that multiple times websocket got disconnected. Is there a possibility that these disconnections and re-connections did not perform a proper connection cleanup leading to more than 3 active connection?
    if yes what could be solution in this case?

    @sujith can you please with this
  • sujith
    Are you sure you are disconnecting properly? It could be because you have not closed the connection at your end but server has an active state at its end and hence you are getting too many requests.
  • iamshaurya
    I am using java client of kite, so is there a way to do a clean close of connection in case of abrupt disruption ?
  • sujith
    I think that is very difficult to solve because on the client machine it is disconnected. I think it is better to check why it is getting disconnected in the first place. One shouldn't block the thread that is receiving ticks.
    If you have taken care of that then add try catch blocks in secondary thread.
  • iamshaurya
    i have deployed my code on aws ec2 instance, i think disconnection could be because of some network fluctuations (maybe).
    My main thread which receives tick data is not blocked from rest of the code, it only receives tick data and pushes it into another queue.
    If i invalidate my session and do a fresh connection then connection count be reset ?
  • rakeshr
    If i invalidate my session and do a fresh connection then connection count be reset ?
    Yes, the connection count is set to the session.
  • Dileep
    Dileep edited September 9
    If i invalidate my session and do a fresh connection then connection count be reset ?
    Hi @rakeshr @iamshaurya How to implement to close and reconnect the session? can you provide any sample code will be much helpful.
Sign In or Register to comment.