Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSE connection never close when not using async iterable #75

Open
sinedied opened this issue Jul 28, 2023 · 2 comments
Open

SSE connection never close when not using async iterable #75

sinedied opened this issue Jul 28, 2023 · 2 comments

Comments

@sinedied
Copy link
Contributor

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
Copy link
Contributor Author

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.

sinedied added a commit to sinedied/fastify-sse-v2 that referenced this issue Jul 28, 2023
@mpetrunic
Copy link
Owner

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

@mpetrunic mpetrunic reopened this Jul 31, 2023
@sinedied sinedied changed the title SSE connection never closer when not using async iterable SSE connection never close when not using async iterable Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants