Skip to content

Conversation

@vinceglb
Copy link
Contributor

What kind of change does this PR introduce?

By introducing a mutex in the Realtime class, we ensure that the connect() method is never executed concurrently.

What is the current behavior?

Bug fix #478. If we call multiple times the connect() method at the same time, realtime feature can lead to an unpredictable behavior.

What is the new behavior?

We ensure that the connect() method is never executed concurrently.

Additional context

I used this documentation to help me choose Mutex as a solution: https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html#mutual-exclusion

The method newSingleThreadContext is not available on the common target, so Mutex seems to be the best option.

Copy link
Collaborator

@jan-tennert jan-tennert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jan-tennert jan-tennert merged commit cd1c961 into supabase-community:master Feb 19, 2024
@vinceglb vinceglb deleted the concurrent-realtime-connect-calls branch February 19, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Concurrent connect() to Realtime can lead to instabilities

2 participants