Adding finally clause to make sure Prometheus indicators are ok

This commit is contained in:
David Négrier 2020-06-29 22:56:41 +02:00
parent 31846d1640
commit 6412c56fcd
1 changed files with 14 additions and 11 deletions

View File

@ -295,20 +295,23 @@ export class IoSocketController {
leaveRoom(Client : ExSocketInterface){ leaveRoom(Client : ExSocketInterface){
// leave previous room and world // leave previous room and world
if(Client.roomId){ if(Client.roomId){
Client.to(Client.roomId).emit(SockerIoEvent.USER_LEFT, Client.userId); try {
Client.to(Client.roomId).emit(SockerIoEvent.USER_LEFT, Client.userId);
//user leave previous world //user leave previous world
const world : World|undefined = this.Worlds.get(Client.roomId); const world: World | undefined = this.Worlds.get(Client.roomId);
if(world){ if (world) {
world.leave(Client); world.leave(Client);
if (world.isEmpty()) { if (world.isEmpty()) {
this.Worlds.delete(Client.roomId); this.Worlds.delete(Client.roomId);
}
} }
//user leave previous room
Client.leave(Client.roomId);
} finally {
this.nbClientsPerRoomGauge.dec({ host: os.hostname(), room: Client.roomId });
delete Client.roomId;
} }
//user leave previous room
Client.leave(Client.roomId);
this.nbClientsPerRoomGauge.dec({ host: os.hostname(), room: Client.roomId });
delete Client.roomId;
} }
} }