mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
fix(session): prevent task cancellation race condition in stop method
The fix properly cancels the recv_task and suppresses CancelledError when awaiting it during session shutdown. This resolves the "read() called while another coroutine is already waiting for incoming data" RuntimeError that occurred when stopping sessions during reconnection attempts. Signed-off-by: wulan17 <wulan17@komodos.id>
This commit is contained in:
parent
01e7717e52
commit
b8028541c9
1 changed files with 4 additions and 1 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
import asyncio
|
||||
import bisect
|
||||
import contextlib
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
|
|
@ -179,7 +180,9 @@ class Session:
|
|||
await self.connection.close()
|
||||
|
||||
if self.recv_task:
|
||||
await self.recv_task
|
||||
self.recv_task.cancel()
|
||||
with contextlib.suppress(asyncio.CancelledError):
|
||||
await self.recv_task
|
||||
|
||||
if not self.is_media and callable(self.client.disconnect_handler):
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in a new issue