-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Server not shutting down and SSE events not disconnecting and retrying correctly - when enableShutdownHooks used with @Sse #9517
Comments
Came across this issue and decided to try it on my repo as well. Turns out I can readily reproduce it on both Windows (Windows 10 Build 19043) and macOS (macOS Monterey Version 12.4). Steps to reproduce:
Expected behavior:
Observed behavior:
Furthermore, I noticed if I kill the client as well, or if I kill the terminal that was used to start the server, that's when I finally get the expected behavior above. Not entirely sure what to make of this piece but it's worth sharing. EDIT: This issue still persists with Nest 9.0 |
I also noticed even if I call |
between this issue and #10131 it seems like the shutdown hook isn't quite trying hard enough. What happens with websockets with gateways? Does it shut those down properly including connected clients? I know plenty of clients have reconnect operations that might mean the server wouldn't shut down there as well. |
I will take a look at this, this week. We will need to keep track of open connections/sockets on our |
Let's track this here #10345 |
Is there an existing issue for this?
Current behavior
See the repository I've added
It has a client and a server
The client is a simple app made with
create-react-app
it just listens to the event source at/sse
.The server is a starter app made with
nest new
.If you start both the client and the server and open a browser at localhost:3001 with the developer tools console open, you can see the status of the event source being logged every few seconds, as well as the messages received from the server being logged.
If you now stop the server - ending the process using
ctrl+c
, the event source should be unexpectedly closed and the client should try to reconnect. But it doesn't - it continues to think the event source still exists - and it receives messages from it.If you go into
/server/src/main.ts
and comment out line 9app.enableShutdownHooks();
and repeat the above steps - you'll see it behave as expected, when you then restart the server the client correctly reconnects.Minimum reproduction code
https://github.com/johnjesse/Nest-issue-repro
Steps to reproduce
See above
Expected behavior
The SSE event should close on the server side, so the client will then try and reconnect - and no longer receive events from the terminated source.
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
^8.0.0
Packages versions
Node.js version
17.8.0
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: