mpetrunic / fastify-sse-v2

Provide Server-Sent Events to Fastify
MIT License
97 stars 19 forks source link

SSE connection never close when not using async iterable #75

Open sinedied opened 1 year ago

sinedied commented 1 year ago

When trying your examples with fastify@4.0.0, only the async iterable one ever completes.

The exemples with individual events works for sending events, but the connection is kept open and never closes. Is there something I missed? Should I close the connection manually from the server? If so, how to do it?

I put up an example repo to illustrate this: https://github.com/sinedied/fastify-sse-test/blob/main/src/routes/test/index.ts

After running the server, run these URLs in a browser:

sinedied commented 1 year ago

Ok after digging into your source code, I found the solution: after the individual reply.sse() are completed, you need to call reply.sseContext.source.end() to end the stream.

This probably should be in the readme docs, took me a while to figure it out.

mpetrunic commented 1 year ago

Thank you for PR, i will keep this issue open, to solve it more elegantly when I catch some time^^