aio-libs / aiohttp-sse

Server-sent events support for aiohttp
Other
192 stars 35 forks source link

Cancel ping_task on connection failure while sending event #450

Closed Olegt0rr closed 5 months ago

Olegt0rr commented 5 months ago

When attempting to execute EventSourceResponse.send(), the connection may be interrupted, resulting in a ConnectionResetError (for example, if the client closed the browser).

Already at this moment we know that the connection is closed and cannot be restored.

But EventSourceResponse._ping_task is still working... When the EventLoop pays attention to the Task, the _ping_task will try to send a : ping to the closed connection.

Because the actions performed by the Task are doomed to failure in advance, we can free him from useless work and cancel the Task on send() failure