Skip to content

Commit cdfb73c

Browse files
committed
Hot fix metadata leek from the space (workadventure#4578)
* Hot fix metadata leek from the space
1 parent eece71d commit cdfb73c

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

back/src/Model/Space.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export class Space implements CustomJsonReplacerInterface {
9191
sourceWatcher
9292
);
9393
debug(`${this.name} : user => removed ${id}`);
94+
95+
if (usersList.size === 0) {
96+
this.users.delete(sourceWatcher);
97+
}
9498
}
9599

96100
public updateMetadata(watcher: SpacesWatcher, metadata: { [key: string]: unknown }) {

back/src/Services/SocketManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,11 @@ export class SocketManager {
14541454
const space = this.spaces.get(removeSpaceUserMessage.spaceName);
14551455
if (space) {
14561456
space.removeUser(pusher, removeSpaceUserMessage.userId);
1457+
if (space.canBeDeleted()) {
1458+
debug("[space] Space %s => deleted", space.name);
1459+
this.spaces.delete(space.name);
1460+
pusher.unwatchSpace(space.name);
1461+
}
14571462
}
14581463
}
14591464

back/tests/Space.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,14 @@ describe("Space", () => {
143143

144144
space.removeUser(watcher1, 1);
145145

146+
// should return false because Space is not empty
147+
expect(space.canBeDeleted()).toBe(false);
148+
146149
// should have received the removeUser event
147150
expect(eventsWatcher3.some((message) => message.message?.$case === "removeSpaceUserMessage")).toBe(true);
148151
space.removeWatcher(watcher3);
149152
});
150-
it("should return false because Space is not empty", () => {
151-
expect(space.canBeDeleted()).toBe(false);
153+
it("should return true because Space is empty at the end (watcher1, watcher2 and watcher3 as removed)", () => {
154+
expect(space.canBeDeleted()).toBe(true);
152155
});
153156
});

play/src/pusher/services/SocketManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,12 +1333,12 @@ export class SocketManager implements ZoneEventListener {
13331333
if (space) {
13341334
space.removeClientWatcher(client);
13351335
space.removeUser(socketData.spaceUser.id);
1336+
this.deleteSpaceIfEmpty(space);
13361337
const success = socketData.spaces.delete(space.name);
13371338
if (!success) {
13381339
console.error("Could not find space", spaceName, "to leave");
13391340
Sentry.captureException(new Error("Could not find space " + spaceName + " to leave"));
13401341
}
1341-
this.deleteSpaceIfEmpty(space);
13421342
} else {
13431343
console.error("Could not find space", spaceName, "to leave");
13441344
Sentry.captureException(new Error("Could not find space " + spaceName + " to leave"));

0 commit comments

Comments
 (0)