Closed johnjesse closed 2 years ago
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:
https://github.com/KasimAhmic/minimon
yarn run init
in the project rootyarn start:client
yarn start:server
Ctrl + C
in terminal 2 (the server)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 Eventsource.close()
on the client side, the request will only terminate after the timeout set in the container settings and keeps using resources.
between this issue and https://github.com/nestjs/nest/issues/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 httpServer
instances. And when closing our httpServer
, these open connections need to be destroyed.
Let's track this here https://github.com/nestjs/nest/pull/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 withnest 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
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