aio-libs / aiohttp-sse

Server-sent events support for aiohttp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Integrating aiohttp-sse with Dash EventSource

sola-ed opened this issue · comments

Hey guys,

Dash EventSource uses starlette EventSourceResponse in the backend to illustrate that Dash component. However, I would rather like to use aiohttp. I have noted that the implementation of aiohttp-sse is pretty similar to the starlette one ... but the former doesn't work.

Following your hello example, the resp.send(data) doesn't trigger the Dash callback, and, after receiving a sequence of requests from the Dash EventSource component, the following error appears:

ConnectionResetError: Cannot write to closing transport

Does anyone know how to successfully run the given example in aiohttp-sse using the Dash EventSource component instead of the /index route? Thanks in advance!

Isn't the Dash component dealing with the client-side connection. i.e. It should be completely agnostic to the server implementation?
So, if you can show your code works with vanilla JS in a browser, and doesn't work with Dash, then that's almost certainly a bug in Dash that should be reported.

I agree that it should be agnostic to server implementation. What I don't get is what sse-starlette is doing differently to produce the correct output format expected by Dash (I checked that the provided example works). A hint might be in this post suggesting that the format data: {} \r\n\r\n\r\n should have 3x\r\n instead of 2x, as in aiohttp-sse?

Why 3?

A message is terminated by a blank line (two line terminators in a row).

https://datatracker.ietf.org/doc/html/rfc8895#section-3.4

A hint might be in this post suggesting that the format data: {} \r\n\r\n\r\n should have 3x\r\n instead of 2x, as in aiohttp-sse?

I'm afraid that if it works correctly in a browser and (as @Olegt0rr pointed out) follows the spec for SSE correctly, then it is clearly a bug in Dash. The linked post says Dash fails to work with any SSE library except sse-starlette, in other words it only works with something which is not valid SSE. Unless you can provide evidence that something is wrong here, then Dash needs to fix their implementation, so does sse-starlette (at which point Dash will have 0 working libraries and will be forced to fix their implementation regardless).