Skip to content

Commit

Permalink
fix: Properly close connections when process terminates
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Sep 11, 2024
1 parent 10ba1bf commit e35b305
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions websocket_server/ServerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class ServerManager {

constructor(config) {
this.config = config
this.closing = false
this.tokenGenerator = new SharedTokenGenerator()
this.apiService = new ApiService(this.tokenGenerator)
this.storageManager = StorageManager.create(this.config.storageStrategy, this.apiService)
Expand Down Expand Up @@ -63,9 +64,12 @@ export default class ServerManager {
}

async gracefulShutdown() {
if (this.closing) return
this.closing = true
console.log('Received shutdown signal, saving all data...')
try {
await this.roomDataManager.removeAllRoomData()
this.socketManager.io.close()
console.log('Closing server...')
this.server.close(() => {
console.log('HTTP server closed.')
Expand Down
2 changes: 1 addition & 1 deletion websocket_server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
STORAGE_STRATEGY = 'lru',
} = process.env

const FORCE_CLOSE_TIMEOUT = 60 * 60 * 1000
const FORCE_CLOSE_TIMEOUT = 60 * 1000

async function main() {
try {
Expand Down

0 comments on commit e35b305

Please sign in to comment.