8000 Fix memory leak in room-deleted presence event by sylvainpolletvillard · Pull Request #2979 · keldaanCommunity/pokemonAutoChess · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix memory leak in room-deleted presence event #2979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/rooms/game-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ export default class GameRoom extends Room<GameState> {
}) {
logger.info("Create Game ", this.roomId)

this.presence.subscribe("room-deleted", (roomId) => {
if (this.roomId === roomId) {
this.disconnect(CloseCodes.ROOM_DELETED)
}
})
this.>
this.presence.subscribe("room-deleted", this.onRoomDeleted)

this.setMetadata(<IGameMetadata>{
name: options.name,
Expand Down Expand Up @@ -650,6 +647,7 @@ export default class GameRoom extends Room<GameState> {

async onDispose() {
logger.info("Dispose Game ", this.roomId)
this.presence.unsubscribe("room-deleted", this.onRoomDeleted)
const playersAlive = values(this.state.players).filter((p) => p.alive)
const humansAlive = playersAlive.filter((p) => !p.isBot)

Expand Down Expand Up @@ -1167,4 +1165,10 @@ export default class GameRoom extends Room<GameState> {
}
})
}

onRoomDeleted(roomId) {
if (this.roomId === roomId) {
this.disconnect(CloseCodes.ROOM_DELETED)
}
}
}
16 changes: 9 additions & 7 deletions app/rooms/preparation-room.ts
7453
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,10 @@ export default class PreparationRoom extends Room<PreparationState> {

this.>
this.presence.subscribe("server-announcement", this.onServerAnnouncement)

this.>
this.presence.subscribe("game-started", this.onGameStart)

this.presence.subscribe("room-deleted", (roomId) => {
if (this.roomId === roomId) {
this.disconnect(CloseCodes.ROOM_DELETED)
}
})
this.>
this.presence.subscribe("room-deleted", this.onRoomDeleted)
}

async onAuth(client: Client, options, context) {
Expand Down Expand Up @@ -428,6 +423,7 @@ export default class PreparationRoom extends Room<PreparationState> {
this.dispatcher.stop()
this.presence.unsubscribe("server-announcement", this.onServerAnnouncement)
this.presence.unsubscribe("game-started", this.onGameStart)
this.presence.unsubscribe("room-deleted", this.onRoomDeleted)
}

onServerAnnouncement(message: string) {
Expand All @@ -451,6 +447,12 @@ export default class PreparationRoom extends Room<PreparationState> {
}
}

onRoomDeleted(roomId) {
if (this.roomId === roomId) {
this.disconnect(CloseCodes.ROOM_DELETED)
}
}

updatePlayersInfo() {
this.setMetadata({
playersInfo: [...this.state.users.values()].map(
Expand Down
0