Skip to content

[Bug]: Resubscribe fails when access token is expired #906

Open
@sproctor

Description

@sproctor

General Info

  • I checked for similar bug report
  • I am using the latest version
  • I checked the troubleshooting page for similar problems

Version(s)

3.0.14

Kotlin Target(s) and their respective versions

JVM 21, Android 15

What happened? (include your code)

Resumed app and immediately started subscriptions. Connected to realtime socket before sessionStatus was updated. RealtimeChannelImpl attempts to join with expired token and gets: Received message without event: RealtimeMessage(topic=realtime:db-changes, event=phx_reply, payload={"status":"error","response":{"reason":"Token has expired 59 seconds ago"}}, ref=null)

val channel = supabase.realtime.channel("db-changes")
try {
  tables.forEach { table ->
      channel.postgresChangeFlow<PostgresAction>(schema = "public") {
        this.table = table
        filter(FilterOperation("account_id", FilterOperator.EQ, accountId))
    }
          .onEach {
              syncTable(table)
          }
          .launchIn(this)
  }
  channel.subscribe(true)
  launch {
      supabase.realtime.status.collectLatest { status ->
          syncAllTables()
      }
  }
  awaitCancellation()
} catch (e: Exception) {
  logger.i(e) { "subscription cancelled" }
  throw e
} finally {
  withContext(NonCancellable) {
      channel.unsubscribe()
      supabase.realtime.removeChannel(channel)
  }
}

Steps To Reproduce (optional)

  1. Get access token
  2. put app in background
  3. Wait until access token expires
  4. Resume app and start subscriptions before access token can be updated

Relevant log output (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions