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

Unable to close fastify server with open connections #88

Open
giovanni-bertoncelli opened this issue Jan 30, 2024 · 5 comments
Open

Unable to close fastify server with open connections #88

giovanni-bertoncelli opened this issue Jan 30, 2024 · 5 comments

Comments

@giovanni-bertoncelli
Copy link

giovanni-bertoncelli commented Jan 30, 2024

I'm reporting a bug discussed here: fastify/help#988.
It seems that fastify-socket.io is missing some logic like the one illustrated here with fastify-websocket: https://github.com/fastify/fastify-websocket/blob/431cba461f0bdd133d607deee6cfc56b69ea379a/index.js#L155-L172.

Description

When a fastify instance gets closed the fastify-socket.io plugin never closes its underlying websocket connections so the server hangs indefinitely. There should be some logic that forces the plugin to close at least the local sockets in order to close correctly the underlying HTTP server.

Reproduction

In order to reproduce the issue you can use this example https://codesandbox.io/p/devbox/socketio-close-stuck-jlcglp, and following these steps:

  • Start the server on a terminal with npm start
  • Start another server and run node client.js
  • Try close with CTRL+C the first terminal: the shutdown process will time out.

Proposal

I'd like to have some forceClose parameter in order to close the local websockets by using socket.io API:

fastify.io.local.disconnectSockets(true);

Or, since fastify has already a parameter for this check whenever forcecloseconnections is true and force the disconnection.

Another option can be some preClose parameter with a design similar to the mentioned fastify-websocket.

@giovanni-bertoncelli
Copy link
Author

@alemagio @matteovivona any thoughts on this?

@alemagio
Copy link
Collaborator

Hi @giovanni-bertoncelli, the plugin adds an hook to make sure that the socket is closed when the fastify instance is closed.
I'll have a look if there is a bug.

@giovanni-bertoncelli
Copy link
Author

Yes, I saw that.. but onClose hook gets never called since the server never closes when there are connections hanging.. You can reproduce that very easily with the codesandbox I've linked.

@giovanni-bertoncelli
Copy link
Author

I can make a PR if you want

@alemagio
Copy link
Collaborator

Sure, it would be great 😄

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