Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failed: You can only track your presence after subscribing to the channel. Did you forget to call channel.subscribe()? #622

Open
2 tasks done
arbyruns opened this issue Dec 6, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@arbyruns
Copy link

arbyruns commented Dec 6, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I've noticed that an increase of assert crash Assertion failed: You can only track your presence after subscribing to the channel. Did you forget to call channel.subscribe()? even though I'm calling subscribe()

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Launch app
  2. Ensure presence is configured for when the user launches the app

Expected behavior

Crash does not occur

Screenshots

image

System information

SupabaseSDK 2.20.5

Additional context

My function

    func setUserPresence() async {
        var isTracked = false

        let deviceId = UIDevice.current.identifierForVendor?.uuidString ?? "unknown-user"

        let realtime = supaBaseClient.realtimeV2
        let userPresence = supaBaseClient.channel("user_presence")
        let presenceStream = userPresence.presenceChange()
        await userPresence.subscribe()

        for await presence in presenceStream {
            // Handle joins
            if !presence.joins.isEmpty && !isTracked {
                await userPresence.track(
                    state: [
                        "user": .string(deviceId),
                        "onlineAt": .double(Date().timeIntervalSince1970)
                    ]
                )
                isTracked = true // Update the state
            }

            // Handle leaves
            if !presence.leaves.isEmpty && isTracked {
                await userPresence.untrack()
                isTracked = false // Update the state
            }
        }
    }
@arbyruns arbyruns added the bug Something isn't working label Dec 6, 2024
@grdsdev
Copy link
Collaborator

grdsdev commented Dec 10, 2024

Hi @arbyruns,

Did you notice this assertion increases after an update? Which version were you before if that is the case?
Also, please make sure nothing has changed in your code that could lead to this increase.

Thanks

@arbyruns
Copy link
Author

Did you notice this assertion increases after an update?

I can't say for sure since this is a new implementation. I was also hitting this with the Android SDK. I've since removed the code from my app because it was chewing through my monthly allotment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants