Skip to content

Commit 7074513

Browse files
committed
2 parents 269676e + fbbcedd commit 7074513

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

server/Server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,17 @@ class Server {
396396
res.sendStatus(200)
397397
}
398398

399+
/**
400+
* Gracefully stop server
401+
* Stops watcher and socket server
402+
*/
399403
async stop() {
400404
Logger.info('=== Stopping Server ===')
401405
await this.watcher.close()
402406
Logger.info('Watcher Closed')
403407

404408
return new Promise((resolve) => {
405-
this.server.close((err) => {
409+
SocketAuthority.close((err) => {
406410
if (err) {
407411
Logger.error('Failed to close server', err)
408412
} else {

server/SocketAuthority.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ class SocketAuthority {
7373
}
7474
}
7575

76+
/**
77+
* Closes the Socket.IO server and disconnect all clients
78+
*
79+
* @param {Function} callback
80+
*/
81+
close(callback) {
82+
Logger.info('[SocketAuthority] Shutting down')
83+
// This will close all open socket connections, and also close the underlying http server
84+
if (this.io)
85+
this.io.close(callback)
86+
else
87+
callback()
88+
}
89+
7690
initialize(Server) {
7791
this.Server = Server
7892

0 commit comments

Comments
 (0)