Skip to content

Commit

Permalink
fix(webserver): Terminate SSE connections on shutdown for a clean shu…
Browse files Browse the repository at this point in the history
…tdown
  • Loading branch information
Hypfer committed Sep 15, 2021
1 parent b7aed1a commit bfbf4dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/lib/webserver/RobotRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class RobotRouter {
getRouter() {
return this.router;
}

shutdown() {
Object.values(this.sseHubs).forEach(hub => {
hub.shutdown();
});
}
}

module.exports = RobotRouter;
1 change: 1 addition & 0 deletions backend/lib/webserver/WebServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class WebServer {
shutdown() {
return new Promise((resolve, reject) => {
Logger.debug("Webserver shutdown in progress...");
this.robotRouter.shutdown();

//closing the server
this.webserver.close(() => {
Expand Down
7 changes: 7 additions & 0 deletions backend/lib/webserver/middlewares/sse/SSEHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class SSEHub {
client.write(payload);
});
}

shutdown() {
this.clients.forEach(client => {
client.terminate();
this.unregister(client);
});
}
}

module.exports = SSEHub;

0 comments on commit bfbf4dd

Please sign in to comment.