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

AsyncTime.schedule_timeout was never awaited #211

Closed
2 tasks done
ritik99 opened this issue Sep 27, 2024 · 2 comments · Fixed by #210
Closed
2 tasks done

AsyncTime.schedule_timeout was never awaited #211

ritik99 opened this issue Sep 27, 2024 · 2 comments · Fixed by #210
Labels
bug Something isn't working

Comments

@ritik99
Copy link

ritik99 commented Sep 27, 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 am trying to run the async version of the supabase realtime client:

s_client = await acreate_client(SUPABASE_URL, SUPABASE_KEY, options=ClientOptions(
        postgrest_client_timeout=100000, 
        storage_client_timeout=100000, 
        schema="public", 
        realtime={"timeout": 100000, "hb_interval": 5}))

await s_client.realtime.connect()
await setup_listeners(s_client)
await s_client.realtime.listen()

setup_listeners subscribes to database changes. I also set up some broadcast channels based on when a user starts typing in an app:

channel = s_client.channel(channel_name, {"config": {"broadcast": {"ack": False, "self": True}}})
await channel.on_broadcast("typing", lambda payload: typing_events_wrapper(chat_id, payload)).subscribe()

However, I receive this error/warning:

ERROR - join push timeout for channel realtime:chat-fbd2adec-f109-495f-ab6a-e8d9ff31ca57
/Users/ritikdutta/Desktop/lib/python3.11/site-packages/realtime/_async/channel.py:88: RuntimeWarning: coroutine 'AsyncTimer.schedule_timeout' was never awaited
  self.rejoin_timer.schedule_timeout()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

which seems to originate from/around line 88 in realtime/_async/channel.py which is calling an async function. The server seems to stop receiving events after this happens.

To Reproduce

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

async def get_supabase_async():
    SUPABASE_URL = os.getenv('SUPABASE_URL')
    SUPABASE_KEY = os.getenv('SUPABASE_API_KEY')
    
    s_client = await acreate_client(SUPABASE_URL, SUPABASE_KEY, options=ClientOptions(
        postgrest_client_timeout=100000, 
        storage_client_timeout=100000, 
        schema="public", 
        realtime={"timeout": 100000, "hb_interval": 5}))
    
    return s_client

def handle_event(payload):
    logger.info(f"received payload: {payload}")

async def test():
    s_client = await get_supabase_async()
    await s_client.realtime.connect()
    channel_name = "test"

    channel = s_client.channel(channel_name, {"config": {"broadcast": {"ack": False, "self": True}}})
    await channel.on_broadcast("typing", lambda payload: handle_event(payload)).subscribe()


async def setup_listeners(s_client):
    await s_client.channel('schema-db-changes').on_postgres_changes("*", schema="public", callback=handle_event).subscribe()

async def main():    
    s_client = await get_supabase_async()

    await s_client.realtime.connect()
    await setup_listeners(s_client)

    await s_client.realtime.listen()

async def main_and_task_manager():
    try:
        await asyncio.gather(main(), test())
    except asyncio.CancelledError:
        logger.info("Tasks cancelled")
    finally:
        logger.info("Cleaning up in main_and_task_manager ...")


if __name__ == "__main__":
    setup_logging(log_file="test.log", mode='w')  # or 'w' to start fresh each time
    try:
        asyncio.run(main_and_task_manager())
    except KeyboardInterrupt:
        logger.info("Keyboard interrupt received. Shutting down...")
    finally:
        logger.info("Server shut down complete.")

Expected behavior

There should be no runtime warnings and the server should continue to receive database events.

Screenshots

If applicable, add screenshots to help explain your problem.

Relevant logs:

Screenshot 2024-09-27 at 1 14 49 PM

System information

  • OS: macOS
  • Version of realtime - 2.0.4
@ritik99 ritik99 added the bug Something isn't working label Sep 27, 2024
@ritik99
Copy link
Author

ritik99 commented Sep 27, 2024

had this issue too but I think it was recently fixed, probably related

@ritik99
Copy link
Author

ritik99 commented Sep 27, 2024

looks like a fix is already in the works lol #210

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

Successfully merging a pull request may close this issue.

1 participant