Reconnect to KiteTicker after TCP error

nkotwar
dear @SRIJAN ,

after I get this error:
Connection Closed !! Reason: connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)
I'm not able to connect to TickerService using kws.connect(threaded = True) .
on_connect() never gets executed, I'm not even receiving any error.

How should I connect to KiteTicker after TCP error?

oh and how should I avoid TCP error in the first place?

Tagged:
  • SRIJAN
    SRIJAN edited July 2022
    Query about TCP error has already been answered in one of your previous threads.

    https://kite.trade/forum/discussion/comment/39433/#Comment_39433

    About the websocket not connecting after this error without throwing error,t's because you are using threaded=True ,so the program exits before it can throw the exception. Try without using threaded=True,or put a sleep after connecting with threaded=True,so the program can properly throw the error.

    The error will be ReactorNotRestartable error from twisted library.

    This is because a twisted reactor is only meant to be started once in a script.
    So,you have to restart your script.
  • nkotwar
    nkotwar edited July 2022
    I was unable to pinpoint issue last time as well.

    You said
    SRIJAN: June 14 :
    This error generally happens due to some internal error in your program which causes the websocket to disconnect.
    But
    [2022-07-12 17:57:29,130] INFO - Connection Closed !! Reason: connection was closed uncleanly (peer dropped
    the TCP connection without previous WebSocket closing handshake)


    as you can see from logs time, this error came @17:57, and I have no logic past 15:30, I unsubscribed from all tokens at 15:30, I also checked, no endpoint was hit post 15:30.
    I'm still unsure, how this "peer dropped TCP connection" happens.
    What type of internal error you might be referring to in this comment?
  • SRIJAN
    SRIJAN edited July 2022
    Any error can cause this. Like, write 1/0 inside on_ticks and the TCP error will occur.

    If you are sure that no error happened in your program,then it might be happening due to really heavy computation.

    You can try queue method as described in solution 1 here instead of threaded ticker.

    https://kite.trade/forum/discussion/comment/25535/#Comment_25535


    Even if this doesn't help,you have to debug yourself.
  • nkotwar
    write 1/0 inside on_ticks and the TCP error will occur.
    This is helpful, now I can catch this error and restart script somehow (if possible) on this event.
    might be happening due to really heavy computation.
    hmm, not sure about this one, as I don't really do anything around the time this error came, anyway.

    Queue method, yeah I do eventually plan to switch to that.

    Thanks again, appreciate you. : )
  • tahseen
    @nkotwar the issue is not the web socket here. That is what you are seeing as an error eventually. But that is not the root cause. Something else in your code causes error and when that results in code breaking up, it throws exception of "connection closed uncleanly"
  • nkotwar
    @tahseen Yeah, with help of Srijan, I figured this is the case.
    Only thing that remains now is locating the root cause of code breaking error, as it happens when neither any calculations are running, nor am I subscribed to any instrument.



    In above image, code broke around 08:06 today morning, after working fine the previous day.
    I hadn't even logged in by that point.
    Subsequent 403 are because of previous day's access token [ignore those]


    For now I'm forced to restart script. Anyway, I'll keep looking for the bug.

  • DD1365
    @nkotwar you need to extensively use try-except to figure out the root cause. Put a numbered exception log in each except and you can easily catch the part/parts which is/are throwing exception.
Sign In or Register to comment.