How to support server side events (sse)
See original GitHub issueI’m experimenting with SSE, and run into the problem that the server keeps on sending data even when the client is gone (or closes the connection). This is problematic, because over time, these zombie tasks will pile up. The same situation would occur with long-polling.
So at first I spawned a task that will call receive()
until it gets "http.disconnect"
and then cancels the task corresponding to the request (the one that sends messages to the client).
But this seems rather awkward, so I took a look at send()
, and saw that this line means that my coroutine happily keeps sending data … into the void, forever.
Would it make sense to replace that return
with a RuntimeError
? Or is there another solution that I overlooked?
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Using server-sent events - Web APIs | MDN
The server-side script that sends events needs to respond using the MIME type text/event-stream . Each notification is sent as a block of ......
Read more >What is Server-Sent Events (SSE) and how to implement it?
Server sent events(SSE) is a pushing technology that enables pushing notification/message/events from the server to the client(s) via HTTP connection.
Read more >HTML SSE API - Server-Sent Events - W3Schools
A server-sent event is when a web page automatically gets updates from a server. This was also possible before, but the web page...
Read more >What Server-Sent Events is - and how and when to implement it
Server -Sent Events is a standard describing how servers can initiate data transmission towards clients once an initial client connection has ...
Read more >Server-sent events - Wikipedia
Server -Sent Events (SSE) is a server push technology enabling a client to receive automatic updates from a server via an HTTP connection,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Already contributed 😉
I recently found the time to look into this again, and added proper support for SSE to Asgineer. As for my original question, the pattern to follow is to let a task receive, as to detect the client from disconnecting. I now see how this is better 😃
For those interested: in Asgineer I added support to be able to sleep the connection: until the connection closes, a timeout expires, or it is woken up. This allows using SSE (and e.g. long-polling) in various ways.
Anyway, this can be closed.