Skip to content

Commit 8801b99

Browse files
committed
Fix stale pong bug
1 parent 1dd1acd commit 8801b99

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/engine/GobanSocket.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,17 @@ export class GobanSocket<
173173
this.socket = this.connect();
174174

175175
this.on("net/pong", ({ client, server }: { client: number; server: number }) => {
176-
if (this.timeout_timer) {
177-
clearTimeout(this.timeout_timer);
178-
this.timeout_timer = undefined;
179-
}
180-
181176
// Ignore pongs from background pings: either we're still in
182177
// background mode, or this is a stale pong that arrived after
183178
// returning to the foreground.
184179
if (
185180
this.options.background_pinging ||
186181
(this.options.ignore_pongs_before && client < this.options.ignore_pongs_before)
187182
) {
183+
if (this.timeout_timer) {
184+
clearTimeout(this.timeout_timer);
185+
this.timeout_timer = undefined;
186+
}
188187
return;
189188
}
190189

@@ -194,6 +193,10 @@ export class GobanSocket<
194193
this.latency = latency;
195194
this.clock_drift = drift;
196195
this.emit("latency", latency, drift);
196+
if (this.timeout_timer) {
197+
clearTimeout(this.timeout_timer);
198+
this.timeout_timer = undefined;
199+
}
197200
});
198201
}
199202

0 commit comments

Comments
 (0)