Skip to content

Fix pending tasks not being cancelled on client close#33

Open
Huguitis wants to merge 5 commits intoxMistt:mainfrom
Huguitis:main
Open

Fix pending tasks not being cancelled on client close#33
Huguitis wants to merge 5 commits intoxMistt:mainfrom
Huguitis:main

Conversation

@Huguitis
Copy link

@Huguitis Huguitis commented Mar 7, 2026

When a client shuts down, any background tasks that were waiting for the client to be ready would get stuck forever, they'd never unblock because the shutdown wasn't waking them up. Python would then forcefully destroy them and log a flood of "Task was destroyed but it is pending!" warnings

Huguitis added 3 commits March 7, 2026 13:50
the ready event is now set before being cleared, which unblocks any tasks currently waiting on wait_until_ready()
friend_event now checks if the client is shutting down right after wait_until_ready() returns and exits early if so
Fix "party not found" not handled
@Huguitis Huguitis marked this pull request as draft March 7, 2026 14:49
@Huguitis
Copy link
Author

Huguitis commented Mar 7, 2026

Still working on a proper fix for this error before it is merged:

future: <Task finished name='Task-105776' coro=<XMPPClient.event_blocklist_remove() done, defined at /home/container/.local/lib/python3.13/site-packages/rebootpy/xmpp.py:464> exception=RuntimeError('Client is closed.')> Traceback (most recent call last): File "/home/container/.local/lib/python3.13/site-packages/rebootpy/xmpp.py", line 472, in event_blocklist_remove data = await self.client.fetch_user(account_id, raw=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/container/.local/lib/python3.13/site-packages/rebootpy/client.py", line 1093, in fetch_user data = await self.fetch_users((user,), cache=cache, raw=raw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/container/.local/lib/python3.13/site-packages/rebootpy/client.py", line 1182, in fetch_users d = await asyncio.gather(*chunk_tasks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/container/.local/lib/python3.13/site-packages/rebootpy/http.py", line 1150, in account_get_multiple_by_user_id return await self.get(r, params=params, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/container/.local/lib/python3.13/site-packages/rebootpy/http.py", line 820, in get return await self.fn_request('GET', route, auth, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/container/.local/lib/python3.13/site-packages/rebootpy/http.py", line 645, in fn_request raise RuntimeError('Client is closed.') RuntimeError: Client is closed.

Wrap fetch_user calls in try/except RuntimeError to handle the case where the XMPP event fires during client shutdown, preventing RuntimeError: Client is closed. crashes
@Huguitis Huguitis marked this pull request as ready for review March 8, 2026 11:37
@Huguitis
Copy link
Author

Huguitis commented Mar 8, 2026

I've tested all the changes and they seem to be working correctly.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant