question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to support server side events (sse)

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
almarkleincommented, Sep 1, 2020

Ping @florimondmanca

Already contributed 😉

1reaction
almarkleincommented, Sep 1, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found