Heartbeat event?
Closed this issue · 7 comments
I have a FastAPI server with sse-starlette for SSE. Everything works smoothly except occasionally, my client would receive an event with data looking like a timestamp:
data= 2023-04-07 23:36:05.744043
data= 2023-04-07 23:36:20.893051
I checked my server code and can be 100% sure that my server never sent events with these data. What could be the reason? How can I filter/ignore them?
Thanks @paxcodes ! I believe I found what you were referring to:
sse-starlette/sse_starlette/sse.py
Line 275 in 30ef55c
However, what's strange is that I've already filtering on event.type
(my server sends event.type='event'
):
async start(controller) {
const onParse = (event: ParsedEvent | ReconnectInterval) => {
if (event.type === 'event') {
const data = event.data;
But I still got the ping event. What do you think might be happening here?
Do I understand your situation correctly?
// client code
if (event.type === 'event') {
const data = event.data;
// !!! data is some sort of timestamp
}
If that is the case, that is strange. How are the events parsed on the client side? Who is providing that event
parameter / ParsedEvent object? An idea is that the client is not parsing the event-stream correctly and setting an incorrect event type.
That assumes that sse-startlette has the expected event-stream text that looks like \r\nevent: ping\r\n
So yes, I would check:
a) What your server is actually sending
b) How your client is parsing what it receives from the server
Using a browser as a client might help you troubleshoot as well because you can have visibility to what the server is sending through the Network tab,
I'm getting the same issue. Can there be an option for just disabling the heartbeat? That would seem logical to me. It's incredibly annoying (and bad design) to always have to parse it out on the client.
EDIT: The best solution I've found is to set the ping to an arbitrarily high number, but there should be an option to disable IMO.
I'll work on a PR to set the ping as a comment
instead so clients don't have to deal with it.