Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
hold strong references to tasks in flight
  • Loading branch information
bdraco committed Oct 27, 2025
commit dc12a014768c2a2eb2f9e56f4a42e513183a8355
4 changes: 4 additions & 0 deletions aiohttp/_websocket/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(
self._output_size = 0
self._compressobj: ZLibCompressor | None = None
self._send_lock = asyncio.Lock()
self._background_tasks: set[asyncio.Task[None]] = set()

async def send_frame(
self, message: bytes, opcode: int, compress: int | None = None
Expand Down Expand Up @@ -99,6 +100,9 @@ async def send_frame(
send_task = asyncio.Task(coro, loop=loop, eager_start=True)
else:
send_task = loop.create_task(coro)
# Keep a strong reference to prevent garbage collection
self._background_tasks.add(send_task)
send_task.add_done_callback(self._background_tasks.discard)
await asyncio.shield(send_task)

# It is safe to return control to the event loop when using compression
Expand Down