supabase-kt icon indicating copy to clipboard operation
supabase-kt copied to clipboard

Don't swallow `CancellationException`

Open sproctor opened this issue 8 months ago • 1 comments

Add checks that the coroutine is still active in places that can catch CancellationException

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

#889

What is the new behavior?

Throws a CancellationException in Exception handling logic. See: https://medium.com/better-programming/the-silent-killer-thats-crashing-your-coroutines-9171d1e8f79b and https://github.com/Kotlin/kotlinx.coroutines/issues/3658 for the rationale.

sproctor avatar Apr 11 '25 14:04 sproctor

Were you able to test if this fixes the problem in #889?

jan-tennert avatar Apr 12 '25 10:04 jan-tennert

It fixes #889. The overall behavior seems to be better, but I'm not sure if it was these changes or something else. I'm still getting:

ClosedReceiveChannelException: Channel was closed
Error while listening for messages. Trying again in 7s

I think that might be unavoidable when the access token expires while connected. I guess I could add some logic to close the connection and refresh the token before it expires if this turns out to be problematic.

Thanks for your help and your work on this.

sproctor avatar Apr 12 '25 13:04 sproctor

I think that might be unavoidable when the access token expires while connected. I guess I could add some logic to close the connection and refresh the token before it expires if this turns out to be problematic.

Well under normal circumstances, this should not happen as this is already handled: https://github.com/supabase-community/supabase-kt/blob/c4163bb495ad5d5b8133ad0a3e523fb5bb7a7fd5/Realtime/src/commonMain/kotlin/io/github/jan/supabase/realtime/RealtimeImpl.kt#L96-L109

The tokens are refreshed via the Auth plugin 20% before their expiration time and Realtime waits for any refreshes or session changes

jan-tennert avatar Apr 13 '25 08:04 jan-tennert