Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): identify on the same socket after a rejected resume

Hampusbc242434ce26
diff --git a/fluxer_app/src/features/gateway/transport/GatewaySocket.ts b/fluxer_app/src/features/gateway/transport/GatewaySocket.ts
index 1b71d3fff..915c4289d 100644
--- a/fluxer_app/src/features/gateway/transport/GatewaySocket.ts
+++ b/fluxer_app/src/features/gateway/transport/GatewaySocket.ts
@@ -50,6 +50,7 @@ const GATEWAY_TIMEOUTS = {
MaxReconnectWhileDispatchesFail: 60000,
ReconnectFloor: 500,
ReconnectSpread: 2000,
+ InvalidSessionIdentifySpread: 1000,
Hello: 20000,
} as const;
@@ -425,6 +426,10 @@ export class GatewaySocket extends EventEmitter<GatewaySocketEvents> {
clearTimeout(this.reconnectTimeoutId);
this.reconnectTimeoutId = null;
}
+ if (this.invalidSessionTimeoutId != null) {
+ clearTimeout(this.invalidSessionTimeoutId);
+ this.invalidSessionTimeoutId = null;
+ }
this.stopHeartbeat();
this.clearSession();
this.consecutiveDispatchFailures = 0;
@@ -1072,6 +1077,10 @@ export class GatewaySocket extends EventEmitter<GatewaySocketEvents> {
clearTimeout(this.invalidSessionTimeoutId);
this.invalidSessionTimeoutId = null;
}
+ if (!isResumable && this.resumeTimeoutId != null) {
+ this.identifyAfterRejectedResume();
+ return;
+ }
const delay = 2500 + Math.random() * 1000;
this.invalidSessionTimeoutId = window.setTimeout(() => {
this.invalidSessionTimeoutId = null;
@@ -1083,6 +1092,17 @@ export class GatewaySocket extends EventEmitter<GatewaySocketEvents> {
}, delay);
}
+ private identifyAfterRejectedResume(): void {
+ this.clearResumeTimeout();
+ this.clearSession();
+ const delay = Math.floor(Math.random() * GATEWAY_TIMEOUTS.InvalidSessionIdentifySpread);
+ this.log.info(`Resume rejected, identifying on the same connection in ${delay}ms`);
+ this.invalidSessionTimeoutId = window.setTimeout(() => {
+ this.invalidSessionTimeoutId = null;
+ this.sendIdentify();
+ }, delay);
+ }
+
private sendIdentify(): void {
this.log.info('Sending IDENTIFY to gateway');
const flags = this.options.identifyFlags ?? 0;