Concurrent connections metric keeps growing (~1,600) while only a few dozen users are active — stale sessions?

Problem/Question
as stated in title concurrent connections metric keeps growing (~1,600) while only a few dozen users are active — stale sessions?

Here are details of how we connect to sdk in our app:
Below is the exact call sequence in our Flutter app, for both versions.

**1. OLD flow (the only version in production when the growth started; live until 30 Sep / 1 Oct), `cometchat_sdk` 5.0.7**

  • **App start (`main`)**: `CometChat.init(appId, AppSettings)` is called once, with `subscriptionType = allUsers` and `autoEstablishSocketConnection = true`.
  • **Every app start and every return to the foreground** (after our own backend session is loaded):
    1. `CometChat.getLoggedInUser()`. If a user is returned, the session is reused and nothing else is called.
    2. Otherwise we fetch an auth token from our backend and call `CometChat.loginWithAuthToken(token)`, with at most one retry on `AUTH_ERR`.
    3. If `logout()` was called earlier in the same app run, `CometChat.init()` is called again before login, because logout cancels the SDK’s native event streams.
    4. `addMessageListener` / `addConnectionListener` are registered once.
  • **`CometChat.connect()` / `CometChat.disconnect()`**: **never called.** Opening, closing and reconnecting the socket was left entirely to the SDK.
  • **Background / foreground**: we called nothing. The SDK closed and reopened the socket by itself.
  • **Logout from our app**: `removeMessageListener`, then `CometChat.logout()`. There was no explicit `disconnect()`.

**2. CURRENT flow (released 30 Sep Android / 1 Oct iOS)**

We introduced this to reduce the number of open sockets: a socket is now open only while a chat screen is visible.

  • **App start**: `CometChat.init()` with `subscriptionType = none` and `autoEstablishSocketConnection = false`. The connection listener is attached once, right after init.
  • **Login**: the same `getLoggedInUser()` → `loginWithAuthToken()` chain as before, on app start and on return to the foreground.
  • **`CometChat.connect()`** is called when the first chat screen opens (chat list, one-on-one or group chat), and only if the user is logged in, the app is in the foreground, and the status is not already `connected`/`connecting`.
  • **`CometChat.disconnect()`** is called:
    • 25 s after the last chat screen is closed;
    • right away if the SDK opens a socket by itself (for example during login or on return from background) while no chat screen is open;
    • on logout, **before** `CometChat.logout()`, because we observed that `logout()` does not close the socket.
  • As a safety net, 2 s after login and after every return to the foreground we read the connection status and fix the state if the connection listener did not fire.
  • **Background**: our timers are cancelled; the SDK closes the socket by itself.
  • **Logout**: `disconnect()` → `removeMessageListener` → `CometChat.logout()`.

**SDK behaviour we observed** :

  1. The SDK closes the socket by itself about 0.5 s **before** the app reports going to background.
  2. On return to the foreground the SDK **reconnects by itself even with `autoEstablishSocketConnection = false`**. That is why we call `disconnect()` immediately when no chat screen is open (step 5 in the log).
  3. `CometChat.logout()` does not close an open socket.

In the old implementation, items 1–3 were fully in the SDK’s hands. Any connection that the SDK opened and that was not properly closed on your side would stay counted.

Chat API/SDK Information
Flutter cometchat_sdk 5.0.8

Reproduction Steps
it is issue with my integrtion, maybe other users have the same

Frequency
it is happening right now

Impact
High