Concurrent connections spiked for no clear reason: how do I ensure connections are properly closed in React Native applications?

Problem and Question
I ran into a surprising issue this morning. My development application spiked to 83 concurrent connections overnight. I’m using 3 device simulators and 1 physical device, and no one else has my application ID.

I am not explicitly closing the connection, and it’s not clear how or when I would do that. I’m following the instructions here and I referenced the UIKit React Native sample app. The only explicit calls to disconnect in those are when the user explicitly logs out.

I don’t expect my users to explicitly logout under normal circumstances. I would expect the UIKit to handle disconnecting and reconnecting when the app is put in the background. Is that wrong?

What are others doing? Has anyone else seen this issue?


[UIKit Version]

    "@sendbird/chat": "^4.9.5",
    "@sendbird/react-native-scrollview-enhancer": "^0.2.1",
    "@sendbird/uikit-react-native": "^3.0.4",
    "@sendbird/uikit-react-native-foundation": "^3.0.4",

[Reproduction Steps]
No clue how it happened.

[Frequency]
I’ve been noticing since I started testing that the concurrent connections looked a little higher than I would expect given that I do most testing on one simulator. However, the massive spike happened for the first time last night.

[Current impact]
It locked me out of my developer account and made it impossible to continue using it. I was advised to create a new developer account by my account rep.

@curthipster Hi
I’m sorry to surprise you.
It seems that the plan was affected by the spike of the PC metric, but the analysis by the development team is needed.
It will take some time, so could you test it with a new account first for testing?
We will update you when the issue is resolved.

Confirmed that I am continuing development with a new account. Thank you for looking into it, and in parallel, is there someone that confirm that I should not be explicitly disconnecting in the react native application? And if that’s wrong, point me to documentation or code in the sample app that gives an example?

Related question: is the connect function returned by useConnection designed to be idempotent? If it is called while the SDK is already in a connected state, does it create a duplicate connection?

It doesn’t matter if you explicitly disconnect.
If the SDK is already connected, it will only return successfully because it is connected.

Duplicate connections are not expected.

The engineer in charge checks if we are trying to reconnect from a specific core SDK version.

We will update you after checking the issue.

1 Like

This exact thing happened to me yesterday and my account is now disabled and I’m unable to continue working. It is impossible that I reached max connections as I was not even working with Sendbird at all yesterday and at the time that it happened everything was turned off and I was not even at my computer. If this is an issue with Sendbirds tracking of concurrent connections then it is very concerning as it is a billing metric. If I had moved to a paid plan (which WAS the intention for launch obviously) I would have been charged who knows what for connections I didn’t make.

@curthipster, here are a few questions from our engineer, could you answer?

  • Did the problem occur on a physical device or on a simulator?
  • Is the SendbirdUIKitContainer used only once at the top level in the customer’s code?
  • Are there any parts in the customer’s code where SendbirdUIKitContainer is conditionally rendered? (Cases where mounting and unmounting may occur repeatedly)
  • Is there any part in the customer’s code where the SDK’s reconnect is explicitly called?
  • Have any instances where the issue was reproduced again after the initial occurrence?

Thanks!

Did the problem occur on a physical device or on a simulator?

There were two iOS simulators and one Android emulator running. It happened overnight while I was away from the computer. The app was also backgrounded on my phone. I don’t have any information to know which of them contributed.

  • Is the SendbirdUIKitContainer used only once at the top level in the customer’s code?

Yes it is in the top level component.

  • Are there any parts in the customer’s code where SendbirdUIKitContainer is conditionally rendered? (Cases where mounting and unmounting may occur repeatedly)

It is not conditionally rendered.

  • Is there any part in the customer’s code where the SDK’s reconnect is explicitly called?

No.

  • Have any instances where the issue was reproduced again after the initial occurrence?

No.

Hello. We are monitoring whether the computer is waking up and going to sleep repeatedly due to activities such as background update checks while it is in sleep mode, and whether this is affecting the simulator’s app.

To address the current issue and handle unknown situations, we have added defensive logic in version 3.1.0 of the uikit to explicitly disconnect when the unmounts.

Normally, when the JavaScript context is destroyed, such as during a reload or app termination, all socket connections are closed by React-Native’s core.

You can find more details in this commit: chore: add disconnect on unmount chat context · sendbird/sendbird-uikit-react-native@a657d43 · GitHub

I apologize for any inconvenience.