Skip to content

[Android] Battery optimized network state not reflected correctly on background. #773

@maksimlya

Description

@maksimlya

Environment

System:
OS: macOS 15.6.1
CPU: (10) arm64 Apple M2 Pro
Memory: 136.94 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 20.11.0
path: ~/.nvm/versions/node/v20.11.0/bin/node
Yarn:
version: 1.22.22
path: ~/.nvm/versions/node/v20.11.0/bin/yarn
npm:
version: 10.2.4
path: ~/.nvm/versions/node/v20.11.0/bin/npm
Watchman: Not Found
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 25.0
- iOS 26.0
- macOS 26.0
- tvOS 26.0
- visionOS 26.0
- watchOS 26.0
Android SDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23339.11.2421.12700392
Xcode:
version: 26.0/17A5305k
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.15
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 18.0.0
wanted: 18.0.0
react:
installed: 19.0.0
wanted: 19.0.0
react-native:
installed: 0.79.2
wanted: 0.79.2
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true

Platforms

Android

Versions

  • Android: 15
  • react-native-netinfo: 11.4.1
  • react-native: 0.79.2
  • react: 19.0.0

Description

Some android devices restricts the app from internet completely after being 5 sec on background. This looks to happen on Xiaomi HyperOS 2.0.2.0 Android 15, but 100% this also happens on many other devices with android 15+.

Looking in dev tools when app is on background - can clearly see the internet is completely gone after 5 sec:

  • fetch('https://google.com') - results in 'Network Request Failed'
  • websockets - disconnect (I see it in logs)
  • TCP conenction (implemented via GO lang JSI native layer) - also disconnects / fails to reconnect.

But the lib keep thinking it is online and reachable (running NetInfo.refresh() / NetInfo.fetch() works and returns isConnected/isReachable as true), thus causing issues on the app to think it is still online and try to connect to all the above facilities. How can I improve the reliability on this? Is this known / bug? I found some old tickets from 2019 and 2021, but I don't think it corresponds to current issue, as this is something that started to happen with recent android versions (stricter battery optimization).

Reproducible Demo

Use Android 15+, go to background on any latest rn demo project. See internet is gone after 5 sec, but state of the lib does not changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions