Skip to content

Commit

Permalink
fix: prevent infinite close event if some removeClient method throws
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Jul 17, 2023
1 parent 5518add commit 5e2a12e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/server/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,19 @@ Invalid certificate files, please check your:
if (this._trustedClients.has(client)) {
this._trustedClients.delete(client);
}
// clean context manager, await before cleaning state manager
await this.contextManager.removeClient(client);
// remove client from pluginManager
await this.pluginManager.removeClient(client);
// clean state manager
await this.stateManager.removeClient(client.id);

// if something goes wrong here, the 'close' event is called again and
// again and again... let's just log the error and terminate the socket
try {
// clean context manager, await before cleaning state manager
await this.contextManager.removeClient(client);
// remove client from pluginManager
await this.pluginManager.removeClient(client);
// clean state manager
await this.stateManager.removeClient(client.id);
} catch (err) {
console.error(err);
}
}

// clean sockets
Expand Down

0 comments on commit 5e2a12e

Please sign in to comment.