Skip to content
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

[No QA] Change offline status when Pusher PINGPONG fails #57255

Merged
merged 7 commits into from
Feb 26, 2025
Merged
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
11 changes: 11 additions & 0 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import {isOffline} from '@libs/Network/NetworkStore';
import * as SequentialQueue from '@libs/Network/SequentialQueue';
import NetworkConnection from '@libs/NetworkConnection';
import * as NumberUtils from '@libs/NumberUtils';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import Pusher from '@libs/Pusher';
Expand Down Expand Up @@ -915,6 +916,7 @@ function subscribeToPusherPong() {

// When any PONG event comes in, reset this flag so that checkforLatePongReplies will resume looking for missed PONGs
pongHasBeenMissed = false;
NetworkConnection.setOfflineStatus(false, 'PONG event was recieved from the server so assuming that means the client is back online');
});
}

Expand All @@ -938,6 +940,9 @@ function pingPusher() {
const pingID = NumberUtils.rand64();
const pingTimestamp = Date.now();

// Reset this flag so that checkforLatePongReplies will resume looking for missed PONGs (in the case we are coming back online after being offline for a bit)
pongHasBeenMissed = false;

// In local development, there can end up being multiple intervals running because when JS code is replaced with hot module replacement, the old interval is not cleared
// and keeps running. This little bit of logic will attempt to keep multiple pings from happening.
if (pingTimestamp - lastPingSentTimestamp < PING_INTERVAL_LENGTH_IN_SECONDS * 1000) {
Expand Down Expand Up @@ -972,6 +977,7 @@ function checkforLatePongReplies() {
// When going offline, reset the pingpong state so that when the network reconnects, the client will start fresh
lastPingSentTimestamp = Date.now();
pongHasBeenMissed = true;
NetworkConnection.setOfflineStatus(true, 'PONG event was not received from the server in time so assuming that means the client is offline');
} else {
Log.info(`[Pusher PINGPONG] Last PONG event was ${timeSinceLastPongReceived} ms ago so not going offline`);
}
Expand All @@ -980,6 +986,11 @@ function checkforLatePongReplies() {
let pingPusherIntervalID: ReturnType<typeof setInterval>;
let checkforLatePongRepliesIntervalID: ReturnType<typeof setInterval>;
function initializePusherPingPong() {
// Skip doing the ping pong during tests so that the network isn't knocked offline, forcing tests to timeout
if (process.env.NODE_ENV === 'test') {
return;
}

// Only run the ping pong from the leader client
if (!ActiveClientManager.isClientTheLeader()) {
Log.info("[Pusher PINGPONG] Not starting PING PONG because this instance isn't the leader client");
Expand Down
Loading