Skip to content
Closed
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
12 changes: 10 additions & 2 deletions src/client/ClientGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ export class ClientGameRunner {

private lastMessageTime: number = 0;
private connectionCheckInterval: NodeJS.Timeout | null = null;
private connectionCheckTimeout: NodeJS.Timeout | null = null;
private goToPlayerTimeout: NodeJS.Timeout | null = null;

private lastTickReceiveTime: number = 0;
Expand Down Expand Up @@ -778,7 +779,9 @@ export class ClientGameRunner {

this.isActive = true;
this.lastMessageTime = Date.now();
setTimeout(() => {
this.connectionCheckTimeout = setTimeout(() => {
this.connectionCheckTimeout = null;
if (!this.isActive) return;
this.connectionCheckInterval = setInterval(
() => this.onConnectionCheck(),
1000,
Expand Down Expand Up @@ -984,6 +987,11 @@ export class ClientGameRunner {
this.isActive = false;
this.worker.cleanup();
this.transport.leaveGame();
this.input.destroy();
if (this.connectionCheckTimeout) {
clearTimeout(this.connectionCheckTimeout);
this.connectionCheckTimeout = null;
}
Comment on lines 987 to +994

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if ClientGameRunner and EventBus are reused or recreated per game.

# Search for where ClientGameRunner is instantiated and whether EventBus is passed in.
rg -nC5 'new ClientGameRunner' --type=ts src/

# Check if EventBus is created once or per game.
rg -nC3 'new EventBus' --type=ts src/

Repository: openfrontio/OpenFrontIO

Length of output: 1174


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the client lifecycle and game runner event subscriptions.
sed -n '240,320p' src/client/Main.ts
printf '\n--- ClientGameRunner start/stop area ---\n'
sed -n '820,1025p' src/client/ClientGameRunner.ts
printf '\n--- EventBus implementation ---\n'
fd -a 'EventBus.ts' src

Repository: openfrontio/OpenFrontIO

Length of output: 9230


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the EventBus API and the listener setup/teardown in ClientGameRunner.
sed -n '1,220p' src/core/EventBus.ts
printf '\n--- start() listener registration ---\n'
rg -nC3 'eventBus\.(on|off)|\.bind\(this\)' src/client/ClientGameRunner.ts
printf '\n--- input destroy path ---\n'
rg -nC4 'class InputHandler|destroy\(\)' src/client -g '*.ts'

Repository: openfrontio/OpenFrontIO

Length of output: 6327


Unsubscribe the game runner event handlers in stop()
The client keeps one EventBus for the whole session, so the .bind(this) listeners added in start() will stack across games unless they are removed. Store the bound callbacks (or use arrow fields) and call eventBus.off(...) for MouseUpEvent, MouseMoveEvent, AutoUpgradeEvent, etc.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/ClientGameRunner.ts` around lines 987 - 994, The stop() cleanup in
ClientGameRunner currently tears down transport/input state but leaves the
EventBus listeners registered from start(), so bound handlers will accumulate
across runs. Update ClientGameRunner to retain references to the callbacks
registered for MouseUpEvent, MouseMoveEvent, AutoUpgradeEvent, and the other
start() subscriptions, then remove them with eventBus.off(...) during stop()
before or alongside the existing cleanup. Use the existing start()/stop()
lifecycle in ClientGameRunner to ensure the same bound handlers are unsubscribed
every time.

if (this.connectionCheckInterval) {
clearInterval(this.connectionCheckInterval);
this.connectionCheckInterval = null;
Expand Down Expand Up @@ -1339,7 +1347,7 @@ export class ClientGameRunner {
}

private onConnectionCheck() {
if (this.transport.isLocal) {
if (!this.isActive || this.transport.isLocal) {
return;
}
const now = Date.now();
Expand Down
Loading
Loading