Multiple WebSocket connections disconnecting simultaneously (code 1006, ECONNRESET)

avnikk
Hi all,

I'm experiencing WebSocket disconnections using the Kite Connect API. Here’s what I observed:

Details:
I have two separate WebSocket connections running in parallel, each with a different API key.
Both sockets disconnected at the same time.

TIMING ARE UST
WebSocket 1:
[2025-05-28 11:41:15.714] WARN: WS end event source: "disconnect" detail: {}

WebSocket 2:
[2025-05-28 11:41:10.186] WARN: WS end event source: "disconnect" detail: {}

After disconnect, both sockets show:

WARN: WS end event
source: "close"
detail: {
"type": "close",
"wasClean": false,
"reason": "",
"code": 1006
}
And on reconnect attempt, I sometimes get:
"type": "error",
"message": "read ECONNRESET",
"error": {
"errno": -104,
"code": "ECONNRESET",
"syscall": "read"
}

My network appears stable, and the access tokens are valid.

The connections are to wss://ws.kite.trade using the official API.

Questions:
What are the common reasons for code 1006 (Abnormal Closure) and ECONNRESET errors in this context?
Is this likely a server-side issue, a client/network issue, or API-key/session related?
Is it expected for multiple WebSocket connections (with different API keys) to disconnect at the same time?
Are there any best practices or recommendations to reduce the frequency of these disconnects or ensure more stable connections?
Are there specific heartbeat, keepalive, or reconnection strategies recommended for Kite Connect WebSockets?
Any insights or suggestions would be appreciated. Thanks!
  • sujith
    It could be related to the network issue. It could be because of some exception in another thread or in the script and it results in this the error.
    You may use the inbuilt reconnect feature in the Kite Connect library. The heartbeat listening and reconnection logic is taken care of by the Kite Connect library.
  • avnikk
    Thank you for your response.

    I am already using the Kite Connect library’s built-in reconnect feature, but I’d like to better understand what specifically causes these simultaneous disconnects, especially when my network seems stable and it happens to multiple sockets at once.

    To help debug this if it happens again:

    Are there specific log messages, error codes, or events from the Kite Connect library that would help identify whether it’s a network blip, a server-side disconnect, or an internal exception in the script?

    Is there a way to distinguish between server-side closes (e.g., maintenance or rate limiting) vs. local code exceptions that bubble up as socket closes?

    Are there common patterns or known issues (e.g., API-wide restarts, scheduled maintenance, session limits) that can cause multiple socket connections to drop at once?

    If you have suggestions for increasing diagnostic output or capturing additional information for support, please let me know so I can include that in my logging.

    Thanks for your help!
  • sujith
    It is not a rate limit issue. You would see 429 or too many requests error for rate limits.
    Does it reconnect after you see this error since you have set reconnection true on kiteconnectjs or you have to stop script and re-run?
    Can you try on two different network simultaneously?
Sign In or Register to comment.