Skip to content

Commit

Permalink
Merge pull request #505 from supabase-community/fix-realtime-reconnect
Browse files Browse the repository at this point in the history
Fix realtime reconnecting suspending indefinitely
  • Loading branch information
jan-tennert authored Mar 7, 2024
2 parents 7fd5ecf + dde3823 commit 227b107
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,6 @@ internal class RealtimeImpl(override val supabaseClient: SupabaseClient, overrid
if (reconnect) {
delay(config.reconnectDelay)
Realtime.logger.d { "Reconnecting..." }
} else {
scope.launch {
supabaseClient.pluginManager.getPluginOrNull(Auth)?.sessionStatus?.collect {
if(status.value == Realtime.Status.CONNECTED) {
when(it) {
is SessionStatus.Authenticated -> updateJwt(it.session.accessToken)
is SessionStatus.NotAuthenticated -> {
if(config.disconnectOnSessionLoss) {
Realtime.logger.w { "No auth session found, disconnecting from realtime websocket"}
disconnect()
}
}
else -> {}
}
}
}
}
}
if (status.value == Realtime.Status.CONNECTED) return
_status.value = Realtime.Status.CONNECTING
Expand All @@ -105,8 +88,29 @@ internal class RealtimeImpl(override val supabaseClient: SupabaseClient, overrid
Error while trying to connect to realtime websocket. Trying again in ${config.reconnectDelay}
URL: $realtimeUrl
""".trimIndent() }
disconnect()
connect(true)
scope.launch {
disconnect()
connect(true)
}
}
}

override fun init() {
scope.launch {
supabaseClient.pluginManager.getPluginOrNull(Auth)?.sessionStatus?.collect {
if(status.value == Realtime.Status.CONNECTED) {
when(it) {
is SessionStatus.Authenticated -> updateJwt(it.session.accessToken)
is SessionStatus.NotAuthenticated -> {
if(config.disconnectOnSessionLoss) {
Realtime.logger.w { "No auth session found, disconnecting from realtime websocket"}
disconnect()
}
}
else -> {}
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ kotlin.experimental.tryK2=false
org.jetbrains.compose.experimental.uikit.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true

supabase-version = 2.2.0
supabase-version = 2.2.1

0 comments on commit 227b107

Please sign in to comment.