App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-12-08] [$175] App stays offline after a brief network drop because NO_RADIO never clears

Open mallenexpensify opened this issue 1 week ago • 14 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.39-2 Reproducible in staging?: Yes Reproducible in production?: Unknown If this was caught during regression testing, add the test name, ID and link from BrowserStack: N/A Email or phone of affected tester (no customers): N/A Logs: Full timeline from console logs and Onyx export: https://github.com/Expensify/App/issues/104900#issuecomment-7048759003 Expensify/Expensify Issue URL: N/A Issue reported by: @mallenexpensify Slack conversation (hyperlinked to channel name): N/A

Summary

A short network drop (around 10 seconds) sets the NO_RADIO hard stop in NetworkState.ts. Only a NetInfo isConnected=true event clears it. If that event never comes, the app stays offline. API calls that skip the queue (AuthenticatePusher, OpenInitialSettingsPage, GetMissingOnyxMessages) keep returning 200, but every write stays queued. Full investigation: https://github.com/Expensify/App/issues/104900

Action Performed:

  1. Use the app on Wi-Fi.
  2. Let the network drop for a few seconds (sleep and wake, change networks, or roam between access points).
  3. Keep using the app after the network comes back.

Expected Result:

The app goes back online and sends the queued requests.

Actual Result:

"You appear to be offline" stays on screen for 45+ minutes. Writes (comments, read receipts, ReconnectApp) pile up in networkRequestQueue and never send. isLoadingReportData stays true. No api/Ping is sent after the first failure.

Console log from 2026-11-20 (UTC):

  • 18:18:59: Hard stop: INTERNET_UNREACHABLE, then Hard stop: NO_RADIO.
  • A few seconds later: AuthenticatePusher returns 200 and the app logs INTERNET_UNREACHABLE cleared — a successful request proved connectivity. NO_RADIO stays set.
  • 18:22–18:53: reads keep returning 200. Writes log Request persisted but not flushing — we are offline.
  • ~19:07: after a reload, NetInfo reports isConnected=true and all 8 queued requests return 200.

Workaround:

Reload the app (Cmd+R / Ctrl+R). No need to clear cache or sign out.

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Also seen on the macOS Desktop app (2026-10-23).

Possible fix

When any request succeeds, clear NO_RADIO or call NetInfo.fetch(), the same way INTERNET_UNREACHABLE is cleared now. Another option is to keep api/Ping running while NO_RADIO is set.

Repro idea (untested)

Make NetInfo report isConnected=false and then never report isConnected=true again. For example, on web, stub the browser online event so it never fires after an offline event. Then check that API reads still succeed while the queue stays paused.

Related

  • https://github.com/Expensify/App/issues/104900
  • https://github.com/Expensify/App/issues/93966
  • https://github.com/Expensify/App/issues/89252
  • https://github.com/Expensify/App/issues/105204

Screenshots/Videos

N/A

View all open jobs on GitHub

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @Krishna2323

mallenexpensify avatar Nov 20 '26 19:11 mallenexpensify

Triggered auto assignment to Contributor-plus team member for initial proposal review - @Krishna2323 (External)

Job added to Upwork: https://www.upwork.com/jobs/~022123866020125336006

🤖 Web test steps verification results: ⚠️ partial

Online baseline verified on dev NewDot web. Offline recovery and missed-online-event recovery remain unverified because supported controls provide no safe connectivity fault injection.

Online test message displayed after sending
Step Status
App works onlineInbox loaded and a test message appeared. AddComment, OpenReport, and Ping returned HTTP 200 without reloading.
Online test message displayed after sending
✅
Brief offline period clears and queued writes send after connectivity returns without reloadUnverified: permitted controls could not toggle connectivity.
⚠️
Recovery when the browser online event is missed but API connectivity returnsUnverified: safe event suppression and independent connectivity fault injection were unavailable.
⚠️

Proposal

What is the root cause of that problem?

Medium confidence: App treats NetInfo’s disconnected state as an indefinite hard stop, but successful API requests do not clear that stop. This explains how reads can succeed while writes remain queued.

Code evidence and incident correlation
  1. NetInfo’s isConnected=false sets hasRadio=false; that alone keeps App offline (NetworkState.ts:366–379).
  2. Successful requests clear reachability/failure state, not hasRadio. Once internetUnreachable clears, later successes return early (NetworkState.ts:44–55).
  3. Reads and side-effect requests bypass the persisted write queue (makeRequest.ts:98–116). Writes persist but refuse to flush while offline (SequentialQueue.ts:899–908).
  4. NetInfo cancels reachability polling when it believes no connection exists, explaining why Ping does not independently recover this state (internetReachability.ts:44–67).
  5. Reload resets these in-memory flags (NetworkState.ts:14–19).

This matches the reported client timeline. A separately paused queue can also block writes, but does not explain the explicit offline guards after unpausing.

Limits: Code was inspected at the linked commit, not the reported staging version. The reason NetInfo missed recovery remains unconfirmed; the prolonged loading indicator’s exact update sequence was not independently reproduced.

What changes do you think we should make in order to solve the problem?

Extend successful-request recovery to handle NO_RADIO alone or alongside INTERNET_UNREACHABLE. Restore connectivity state before notifying subscribers, allowing the existing online-transition queue flush to run.

Preserve forced-offline/debug settings and independent queue pauses. Add regression coverage for combined stops, NO_RADIO alone, repeated successes, queued-write flushing, and a genuine subsequent disconnect.

What alternative solutions did you explore? (Optional)

NetInfo.fetch() alone is insufficient: it can return cached state. refresh() resamples browser state, but can still report a stale disconnected heuristic (state.ts:68–107). Recovery must also avoid immediately relatching from repeated stale events.

Likely duplicate: App stays offline after a brief network drop because NO_RADIO never clears contains the same incident timeline. Consolidating the reports would avoid parallel work.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107620) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run · no recording available

MelvinBot avatar Nov 20 '26 19:11 MelvinBot

Proposal

Proposal

Please re-state the problem that we are trying to solve in this issue.

After a brief network drop (e.g. Wi-Fi reconnection, waking from sleep, or roaming between access points), the app remains stuck offline indefinitely with the "You appear to be offline" banner displayed. Subsequent API reads and side-effect calls (such as AuthenticatePusher, OpenInitialSettingsPage, GetMissingOnyxMessages) succeed with HTTP 200 OK, but all write requests remain paused in SequentialQueue because the NO_RADIO hard stop (hasRadio = false) is never cleared.

What is the root cause of that problem?

In src/libs/NetworkState.ts:44-55:

onRequestSuccess(() => {
    if (!internetUnreachable) {
        return;
    }
    Log.info('[NetworkState] INTERNET_UNREACHABLE cleared — a successful request proved connectivity');
    clearHardStops();
    scheduleJitteredReconnect();
});

And in clearHardStops (lines 185–190):

function clearHardStops() {
    internetUnreachable = false;
    sustainedFailuresActive = false;
    resetFailureCounters();
    updateState();
}
  1. When a network connection drops briefly, NetInfo reports state.isConnected === false, which invokes setHasRadio(false) and sets hasRadio = false (logging Hard stop: NO_RADIO — OS reports no network interface).
  2. When the network connection returns, on web/desktop the browser often fails to emit an online event (or NetInfo's internal state fails to re-query the OS network interface without a reload).
  3. Furthermore, when NetInfo believes isConnected === false, it suspends reachability polling (api/Ping is never sent).
  4. Meanwhile, non-queued background reads and pusher authentication bypass the paused sequential queue and succeed with HTTP 200 OK via makeRequest.ts, firing onRequestSuccess() in FailureTracker.ts.
  5. However, onRequestSuccess() in NetworkState.ts only checks if (!internetUnreachable) { return; }. Because internetUnreachable is false, it immediately returns!
  6. Even when clearHardStops() is called, it only resets internetUnreachable = false and sustainedFailuresActive = false, leaving hasRadio = false.
  7. Because hasRadio remains false, getIsOffline() continuously returns true (!hasRadio || ...), keeping the app permanently locked in offline mode and blocking all queued writes from flushing.

What changes do you think we should make in order to solve the problem?

  1. Clear NO_RADIO and all connectivity hard stops when a request succeeds in src/libs/NetworkState.ts: A successful HTTP response from Expensify's servers irrefutably proves that the device has an active radio interface and server reachability.

    Update onRequestSuccess:

    onRequestSuccess(() => {
        // Only run recovery if at least one connectivity hard stop is currently active
        if (hasRadio && !internetUnreachable && !sustainedFailuresActive) {
            return;
        }
    
        if (!hasRadio) {
            Log.info('[NetworkState] NO_RADIO cleared — a successful request proved radio connectivity');
        }
        if (internetUnreachable) {
            Log.info('[NetworkState] INTERNET_UNREACHABLE cleared — a successful request proved connectivity');
        }
        if (sustainedFailuresActive) {
            Log.info('[NetworkState] SUSTAINED_FAILURES cleared — a successful request proved connectivity');
        }
    
        clearHardStops();
        NetInfo.refresh();
        scheduleJitteredReconnect();
    });
    
  2. Update clearHardStops() to restore hasRadio = true:

    function clearHardStops() {
        hasRadio = true;
        internetUnreachable = false;
        sustainedFailuresActive = false;
        resetFailureCounters();
        updateState();
    }
    
    • Calling NetInfo.refresh() synchronizes NetInfo's internal cache with the browser/OS so that subsequent reachability polling and events resume properly.
    • shouldForceOffline and simulatedOffline debug flags are preserved because getIsOffline() evaluates them independently and clearHardStops does not override user debug settings.

What alternative solutions did you explore? (Optional)

  • Relying solely on NetInfo.refresh() or NetInfo.fetch() on timer: Rejected because NetInfo's browser implementation can return cached disconnected state if the browser has not dispatched a native event, and polling introduces unnecessary overhead.
  • Keeping api/Ping running while NO_RADIO is set: Rejected because reachability polling is managed internally by @react-native-community/netinfo, which bypasses reachability checks when isConnected === false. Directly reacting to real request successes in NetworkState is deterministic, immediate, and zero-overhead.

Test Plan

  1. Unit tests (tests/unit/NetworkStateTest.ts):
    • Test that when hasRadio is set to false via setHasRadio(false) (putting the app offline with NO_RADIO), triggering recordSuccess() in FailureTracker:
      • Clears hasRadio (hasRadio becomes true).
      • Clears the offline state (getIsOffline() returns false).
      • Calls NetInfo.refresh() and notifies reconnect listeners.
    • Test that when both NO_RADIO and INTERNET_UNREACHABLE are set, a single request success clears both hard stops simultaneously and restores connectivity.
    • Test that shouldForceOffline: true maintains offline state even if a request success callback is invoked.
  2. Integration / Manual verification:
    • Simulate a network disconnect on Web: toggle network to offline in DevTools, observe "You appear to be offline".
    • Turn network back online without dispatching the browser window online event.
    • Trigger any read request (e.g. switching chats or refreshing settings).
    • Verify that the offline banner disappears immediately and all queued actions in SequentialQueue flush successfully to the server.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c

ayolyn avatar Nov 20 '26 19:11 ayolyn

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 20 '26 19:11 melvin-bot[bot]

This affects many users, not just me. VictoriaLogs, desktop user agents (Mac/Windows, browser or Desktop app), 24h windows:

Nov 18 Nov 20
Users stuck (any duration) 1,578 1,352
Stuck > 5 min 105 109
Stuck > 30 min 31 33

About 9,100 desktop users hit NO_RADIO per day, so roughly 15% get stuck.

"Stuck" means one log batch shows, in order: Hard stop: NO_RADIO, then INTERNET_UNREACHABLE cleared — a successful request proved connectivity, then writes logging persisted but not flushing — we are offline, with no NO_RADIO cleared in between. The network worked, but writes stayed queued.

Example: a Windows/Edge user woke their computer at 01:20 UTC and was still queuing writes as offline at 14:03, almost 13 hours later.

These counts are low: durations are measured within one log batch, and stuck sessions that end in a reload never upload their logs.

VMUI query

mallenexpensify avatar Nov 20 '26 21:11 mallenexpensify

Proposal

Please re-state the problem that we are trying to solve in this issue.

A brief network drop (e.g. sleep/wake or roaming between access points) sets the NO_RADIO hard stop (hasRadio = false) in src/libs/NetworkState.ts. Because only a NetInfo event where isConnected === true can reset hasRadio, if NetInfo fails to emit that event or caches the disconnected state, the app remains permanently stuck offline. Even though non-queued reads (like AuthenticatePusher or OpenInitialSettingsPage) return HTTP 200, all write requests remain queued indefinitely and the "You appear to be offline" banner never clears.

What is the root cause of that problem?

In src/libs/NetworkState.ts:

  1. In onRequestSuccess() (lines 44–51):
    onRequestSuccess(() => {
        if (!internetUnreachable) {
            return;
        }
        Log.info('[NetworkState] INTERNET_UNREACHABLE cleared — a successful request proved connectivity');
        clearHardStops();
        scheduleJitteredReconnect();
    });
    
    onRequestSuccess checks only !internetUnreachable. If NO_RADIO is set (hasRadio === false), onRequestSuccess returns early and does not clear NO_RADIO.
  2. In clearHardStops():
    function clearHardStops() {
        internetUnreachable = false;
        sustainedFailuresActive = false;
        resetFailureCounters();
        updateState();
    }
    
    clearHardStops() clears internetUnreachable and sustainedFailuresActive, but leaves hasRadio untouched.
  3. Therefore, once hasRadio is set to false, a successful HTTP response (which proves device-level radio and network interface connectivity) cannot restore the app to online state. getIsOffline() continues to return true because !hasRadio is true, blocking SequentialQueue from flushing.

What changes do you think we should make in order to solve the problem?

In src/libs/NetworkState.ts: Update onRequestSuccess so that whenever any request succeeds, it clears hasRadio in addition to internetUnreachable:

onRequestSuccess(() => {
    if (!internetUnreachable && hasRadio) {
        return;
    }
    if (!hasRadio) {
        Log.info('[NetworkState] NO_RADIO cleared — a successful request proved connectivity');
        hasRadio = true;
    }
    if (internetUnreachable) {
        Log.info('[NetworkState] INTERNET_UNREACHABLE cleared — a successful request proved connectivity');
    }
    clearHardStops();
    scheduleJitteredReconnect();
});

This ensures that any successful API call acts as an authoritative source of truth for physical radio connectivity, clearing the NO_RADIO hard stop, restoring getIsOffline() to false, and immediately flushing all persisted queued requests via scheduleJitteredReconnect().

What specific scenarios should we test?

  1. Simulate a brief network disconnection where NO_RADIO is triggered (hasRadio = false).
  2. Restore network connectivity without firing a native NetInfo online event.
  3. Execute any read request (or trigger a ping/reconnect).
  4. Verify that NO_RADIO is immediately cleared in the log.
  5. Verify that the "You appear to be offline" banner clears and all queued writes in SequentialQueue flush successfully.
  6. Verify debug options (shouldForceOffline, simulatedOffline) still function as intended and are not overridden.

RajGahoi avatar Nov 21 '26 10:11 RajGahoi

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~017cd1009178a92a66

Proposal

What is the root cause of that problem?

There are two coupled issues in src/libs/NetworkState.ts:

  1. A successful API response never clears NO_RADIO (hasRadio = false):
    • onRequestSuccess (lines 44–51) returns early whenever !internetUnreachable, so if only NO_RADIO is active it exits without doing anything.
    • Even when both NO_RADIO and INTERNET_UNREACHABLE are active, onRequestSuccess calls clearHardStops() (lines 179–184), which clears internetUnreachable and sustainedFailuresActive but leaves hasRadio = false. That matches the production log timeline (Hard stop: NO_RADIO → INTERNET_UNREACHABLE cleared → writes still logged as persisted but not flushing — we are offline).
  2. Stale NetInfo emissions unconditionally re-set NO_RADIO:
    • Unlike isInternetReachable — which tracks prevIsInternetReachable and only triggers setInternetUnreachable(true) on a non-false → false transition (lines 41–43, 378) so stale false events cannot re-lock the app after recovery — the NetInfo listener invokes setHasRadio(radio) unconditionally on every emission (line 372).
    • Because of this, even if onRequestSuccess sets hasRadio = true, any subsequent stale NetInfo emission with isConnected === false (such as NetworkState.refresh() on foreground focus, or calling NetInfo.refresh() during recovery) immediately sets hasRadio = false again and traps the user back in NO_RADIO.

What changes do you think we should make in order to solve the problem?

In src/libs/NetworkState.ts:

  1. Clear NO_RADIO when a real request proves connectivity:
    • Update onRequestSuccess to recover whenever !hasRadio || internetUnreachable (not only internetUnreachable), logging [NetworkState] NO_RADIO cleared — a successful request proved connectivity when !hasRadio was set.
    • Move hasRadio = true into clearHardStops() alongside internetUnreachable = false and sustainedFailuresActive = false (matching onReachabilityRestored() and leaving debug flags shouldForceOffline and simulatedOffline untouched).
    • Do not call NetInfo.refresh() inside onRequestSuccess, since refreshing while the browser/OS still caches isConnected === false would re-emit a stale false state.
  2. Guard NO_RADIO with a prevIsConnected transition check (mirroring prevIsInternetReachable):
    • Track prevIsConnected in NetworkState.ts.
    • In the NetInfo listener, only call setHasRadio(false) when state.isConnected === false && prevIsConnected !== false, and call setHasRadio(true) when radio is true while !hasRadio.
    • Keep prevIsConnected at false when onRequestSuccess clears hasRadio, so repeated stale isConnected === false emissions (e.g. from foreground refresh()) do not re-trigger NO_RADIO, while once NetInfo observes isConnected === true, any future genuine disconnect (true → false) triggers NO_RADIO normally.
  3. Add unit tests in tests/unit/NetworkStateTest.ts and tests/unit/NetworkStateReachabilityTest.ts:
    • Verify onRequestSuccess clears NO_RADIO (both standalone and combined with INTERNET_UNREACHABLE) and brings getIsOffline() back to false while scheduling reconnect.
    • Verify repeated stale isConnected === false emissions (e.g. via refresh()) do not re-enter NO_RADIO after recovery, while a subsequent true → false transition still sets NO_RADIO.
    • Verify shouldForceOffline and simulatedOffline remain unaffected.

What alternative solutions did you explore? (Optional)

  • Calling NetInfo.refresh() inside onRequestSuccess: Rejected because on desktop web/Electron where navigator.onLine or NetInfo's cached state stays false, refreshing immediately re-emits isConnected === false and without a transition guard puts the app right back into NO_RADIO.
  • Ignoring state.isConnected entirely on web/desktop: Rejected because NO_RADIO is still useful as a fast-fail signal on a real true → false network drop; it only needs to yield to proven HTTP connectivity and ignore repeated stale false emissions.

danlopes18-ctrl avatar Nov 21 '26 22:11 danlopes18-ctrl

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 21 '26 22:11 melvin-bot[bot]

I will pick that up as I wrote these mechanisms myself, looking into it today

adhorodyski avatar Nov 23 '26 09:11 adhorodyski

I think I'm onto something and for now everything points me to https://github.com/react-native-netinfo/react-native-netinfo/issues/756 which is upstream. I will run more manual validations and summarize here by EOW.

adhorodyski avatar Nov 25 '26 21:11 adhorodyski

I was able to reproduce the stuck state I believe, opening up PRs we can ship adhocs for you to try @mallenexpensify.

adhorodyski avatar Nov 26 '26 18:11 adhorodyski

@mallenexpensify most importantly I think you should try an adhoc from https://github.com/Expensify/App/pull/108127. I was able to get stuck 5/8 times on its reproduction steps locally, running on Chrome 158 in MacOS without this patch. It's 1:1 the upstream fix and I believe its the correct approach to getting this race condition fixed.

The other bit is https://github.com/Expensify/App/pull/108128 which I think is the other correctness fix to our own code, where we should treat any network success (any READ) as a confirmation of the network being on, no matter what the library says.

Both these should only yield more correct network status resolution, but we should test and deploy them separately.

adhorodyski avatar Nov 26 '26 19:11 adhorodyski

@Krishna2323

The solution for this issue has been :rocket: deployed to production :rocket: in version 9.5.55-6 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

  • https://github.com/Expensify/App/pull/108127

If no regressions arise, payment will be issued on 2026-12-08. :confetti_ball:

The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]

melvin-bot[bot] avatar Dec 01 '26 03:12 melvin-bot[bot]