From cb56120225e3913d3d39d0b3004edfd159bc0ee6 Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Thu, 27 Jun 2024 14:39:52 -0400 Subject: [PATCH 1/3] Incorporate hasPendingNetworkCheck --- src/libs/NetworkConnection.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index acdb982c729a..6cbb0d691732 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -112,6 +112,7 @@ function subscribeToNetInfo(): () => void { reachabilityUrl: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID || 'unknown'}`, reachabilityMethod: 'GET', reachabilityTest: (response) => { + hasPendingNetworkCheck = false; if (!response.ok) { return Promise.resolve(false); } @@ -123,6 +124,13 @@ function subscribeToNetInfo(): () => void { // If a check is taking longer than this time we're considered offline reachabilityRequestTimeout: CONST.NETWORK.MAX_PENDING_TIME_MS, + reachabilityShouldRun: () => { + if (!hasPendingNetworkCheck) { + hasPendingNetworkCheck = true; + return true; + } + return false; + }, }); } From 96f1515320522ee9f521bad34f2180f134fe5c46 Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Fri, 28 Jun 2024 10:10:13 -0400 Subject: [PATCH 2/3] improve logic order --- src/libs/NetworkConnection.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 6cbb0d691732..03dd04d8d444 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -125,11 +125,11 @@ function subscribeToNetInfo(): () => void { // If a check is taking longer than this time we're considered offline reachabilityRequestTimeout: CONST.NETWORK.MAX_PENDING_TIME_MS, reachabilityShouldRun: () => { - if (!hasPendingNetworkCheck) { - hasPendingNetworkCheck = true; - return true; + if (hasPendingNetworkCheck) { + return false; } - return false; + hasPendingNetworkCheck = true; + return true; }, }); } From 23e1484840726604a3f62757e6db74ad491fa9bc Mon Sep 17 00:00:00 2001 From: Srikar Parsi Date: Fri, 28 Jun 2024 10:55:41 -0400 Subject: [PATCH 3/3] remove setting recheckNetInfo in manual check --- src/libs/NetworkConnection.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 03dd04d8d444..d38fd4118cfd 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -204,8 +204,7 @@ function recheckNetworkConnection() { } Log.info('[NetworkConnection] recheck NetInfo'); - hasPendingNetworkCheck = true; - NetInfo.refresh().finally(() => (hasPendingNetworkCheck = false)); + NetInfo.refresh(); } export default {