From bd6f5635329f40b20b98cb80d4c2f45212764cc5 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Tue, 24 Aug 2021 21:04:47 +0530 Subject: [PATCH] Fix race condition in leaving rooms --- lib/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index bf51f80..a59bfd2 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -83,13 +83,13 @@ export class Adapter extends EventEmitter { } private _del(room, id) { - if (this.rooms.has(room)) { - const deleted = this.rooms.get(room).delete(id); + const room = this.rooms.get(room) + if (room != null) { + const deleted = room.delete(id); if (deleted) { this.emit("leave-room", room, id); } - if (this.rooms.get(room).size === 0) { - this.rooms.delete(room); + if (room.size === 0 && this.rooms.delete(room)) { this.emit("delete-room", room); } }