From ed855500c5813e6e6112fc595e39157f01b0980e Mon Sep 17 00:00:00 2001 From: Pedro Rodriguez Date: Mon, 26 Jul 2021 14:01:48 +0200 Subject: [PATCH] Close all connections before exiting erizoJS (#1740) --- erizo_controller/erizoJS/erizoJSController.js | 15 ++++++++------- erizo_controller/erizoJS/models/Client.js | 7 +++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/erizo_controller/erizoJS/erizoJSController.js b/erizo_controller/erizoJS/erizoJSController.js index 141c0f8ff..8a95a9d8e 100644 --- a/erizo_controller/erizoJS/erizoJSController.js +++ b/erizo_controller/erizoJS/erizoJSController.js @@ -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); + } + }); }); }; diff --git a/erizo_controller/erizoJS/models/Client.js b/erizo_controller/erizoJS/models/Client.js index 12d55c734..c18bcc70b 100644 --- a/erizo_controller/erizoJS/models/Client.js +++ b/erizo_controller/erizoJS/models/Client.js @@ -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) {