Skip to content

Commit

Permalink
Close all connections before exiting erizoJS (#1740)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Jul 26, 2021
1 parent 1a85da4 commit ed85550
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 8 additions & 7 deletions erizo_controller/erizoJS/erizoJSController.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ exports.ErizoJSController = (erizoJSId, threadPool, ioThreadPool) => {

Promise.all(removePromises).then(() => {
log.info(`message: removeClient - closing all connections on, clientId: ${clientId}`);
client.closeAllConnections();
clients.delete(client.id);
callback('callback', true);
if (clients.size === 0) {
log.info('message: Removed all clients. Process will exit');
process.exit(0);
}
client.closeAllConnections().then(() => {
clients.delete(client.id);
callback('callback', true);
if (clients.size === 0) {
log.info('message: Removed all clients. Process will exit');
process.exit(0);
}
});
});
};

Expand Down
7 changes: 5 additions & 2 deletions erizo_controller/erizoJS/models/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ class Client extends EventEmitter {
closeAllConnections() {
log.debug(`message: client closing all connections, clientId: ${this.id},`,
logger.objectToLog(this.options), logger.objectToLog(this.options.metadata));
const promises = [];
this.connections.forEach((connection) => {
connection.close();
promises.push(connection.close());
});
return Promise.all(promises).then(() => {
this.connections.clear();
});
this.connections.clear();
}

maybeCloseConnection(id) {
Expand Down

0 comments on commit ed85550

Please sign in to comment.