From 6412c56fcd0472d9a5e00d0d44ba98456cef7172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 29 Jun 2020 22:56:41 +0200 Subject: [PATCH] Adding finally clause to make sure Prometheus indicators are ok --- back/src/Controller/IoSocketController.ts | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index 2ea25f31..102c03fb 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -295,20 +295,23 @@ export class IoSocketController { leaveRoom(Client : ExSocketInterface){ // leave previous room and world 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 - const world : World|undefined = this.Worlds.get(Client.roomId); - if(world){ - world.leave(Client); - if (world.isEmpty()) { - this.Worlds.delete(Client.roomId); + //user leave previous world + const world: World | undefined = this.Worlds.get(Client.roomId); + if (world) { + world.leave(Client); + if (world.isEmpty()) { + 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; } }