Skip to content

Auth listener unsubscribing during notification makes sign_out raise RuntimeError #1642

Description

@hsusul

Describe the bug

An auth-state callback that unsubscribes itself causes sign_out() to raise RuntimeError: dictionary changed size during iteration. Other registered listeners then miss the sign-out event. This affects both SyncGoTrueClient and AsyncGoTrueClient, for example when a one-shot listener unregisters after handling its first event.

Reproduction

No running Supabase instance or credentials are needed:

from supabase_auth import SyncGoTrueClient

client = SyncGoTrueClient(
    url="http://localhost:9998",
    auto_refresh_token=False,
    persist_session=False,
)
received = []

def once(event, session):
    subscription.unsubscribe()

subscription = client.on_auth_state_change(once)
client.on_auth_state_change(lambda event, session: received.append(event))
client.sign_out()
assert received == ["SIGNED_OUT"]

Expected: sign-out completes, the second listener receives SIGNED_OUT, and the unsubscribed listener does not receive subsequent events.

Actual: _notify_all_subscribers() iterates a live dictionary view; subscription.unsubscribe() removes an entry during that iteration, causing RuntimeError before the second listener is called.

Environment

  • Library: supabase_auth 2.31.0
  • Reproduced on upstream main bb7ecc5fb86f5f8729c40a3885c6154d9b9f6262
  • Python: 3.13.12

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions