react-native-netinfo: Netinfo showing wrong status when both wifi and cellular data are active
Environment
info Fetching system and libraries information...
System:
OS: Windows 10 10.0.19042
CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Memory: 2.35 GB / 11.91 GB
Binaries:
Node: 14.16.0 - ~\AppData\Local\Temp\yarn--1627121495445-0.5626842957033094\node.CMD
Yarn: 1.22.5 - ~\AppData\Local\Temp\yarn--1627121495445-0.5626842957033094\yarn.CMD
npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085
Visual Studio: Not Found
Languages:
Java: 11.0.10 - /c/Program Files/AdoptOpenJDK/jdk-11.0.10.9-hotspot/bin/javac
Python: 3.9.2 - ~/AppData/Local/Microsoft/WindowsApps/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz => 0.63.2
react-native-windows: Not Found
npmGlobalPackages:
*react-native*: Not Found
Platforms
Only tested on Android
Versions
- Android: 11.0
- react-native-netinfo: 6.0.0
- react-native: 0.63
- react: 16.13.1
Description
When wifi and cellular data are switched on at the same time netinfo gives wrong info after split seconds. So far only been able to reproduce on my device (One Plus Nord). It works normally if only one of the network is connect i.e either cellular or wifi only.
Here is a video showing what I explained above ->
Reproducible Demo
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 9
- Comments: 34 (14 by maintainers)
Commits related to this issue
- deps: Bring @rnc/react-native-netinfo back down to 6.0.0 6.0.1 introduced a bug, in https://github.com/react-native-netinfo/react-native-netinfo/commit/7084771 , that was causing the "No Internet c... — committed to chrisbobbe/zulip-mobile by chrisbobbe 3 years ago
- deps: Bring @rnc/react-native-netinfo back down to 6.0.0 6.0.1, which we took in 5cc9dfa4a, introduced a bug, in https://github.com/react-native-netinfo/react-native-netinfo/commit/7084771 , that w... — committed to chrisbobbe/zulip-mobile by chrisbobbe 3 years ago
- deps: Bring @rnc/react-native-netinfo back down to 6.0.0 6.0.1, which we took in 5cc9dfa4a, introduced a bug, in https://github.com/react-native-netinfo/react-native-netinfo/commit/7084771 , that w... — committed to chrisbobbe/zulip-mobile by chrisbobbe 3 years ago
I don’t personally have maintainer power here. @matt-oakes ? I’ve never seen anyone else commit. Note that even were I to have maintainer power here to merge something: someone needs to make a PR. This is open source. Don’t just sit there and “me too” issues, roll up your sleeves and do work, that’s how it moves forward.
i have the same issue !!!
What exactly is a native mobile developer? Ask yourself that, then perhaps change your perspective. You have all the tools installed. You are a developer (not a ___ developer), and to fix things just needs a developer (not a ____ developer).
Try things. Experiment. Play around. Learn. Find the problems, fix the problems. That’s just what developers do.
You are the community, and hope is not a plan. Open up the code in the related tools and try things.
@umerqr It’s a big pain to work with react-native if you are not a native mobile developer. We can only rely on the community and hope someday it’s going to work again.
@gnprice there is new activity in this area from @Willham12 in PR #510 - if you have a minute can you please examine that PR, it may be better than the strict revert of #443 by nature of actually removing state and just querying things fresh on events, returning all fresh info. I’d love to know what you think
I’m experiencing the same issue. I can reproduce this on my Android-device by
After step 4, if I try to turn on airplane-mode again, it doesn’t report any state-change so I don’t get notified that the device is offline.
I debugged natively on Android and it looks like it is the Android-part that reports “onLost” when I see the “internet reachable false” in step 5.
Maybe this is relevant: https://gist.github.com/PasanBhanu/730a32a9eeb180ec2950c172d54bb06a.
Edit: Pixel 4, Android 12. RN 0.64.2, NetInfo 6.0.2.
I’m randomly observing a similar issue on Android 9, although may also happen with Android 11, still trying to reproduce.
Turning on/off the WiFi while having a data connection may randomly end up reporting no connection. This started happening after upgrading to RN 0.65 and Android SDK 31. Still trying to reproduce.
That’s a good analysis. The critical part is I think this:
If the change that caused the breakage is not even reliable, then that’s a strong case for revert. Obviously I’d love to see the slightly-more-network-aware/stateful version of 443 implemented but I don’t have the time myself.
Any dissent from 443 revert then? I’ll consider it a sort of “call for comments”. I’ll let it sit for a day or two. Obviously you may revert locally via patch-package in the meantime. If there’s some well-reasoned dissent I/we can hold off. Otherwise if there is no dissent in the next couple days I’ll revert and release.
Thanks very much for thinking through it @gnprice
I’m seeing these symptoms, reproducible with the steps in https://github.com/react-native-netinfo/react-native-netinfo/issues/481#issuecomment-938505186 , after an upgrade from 6.0.0 to 6.0.2.
I took a look at the code in
NetworkCallbackConnectivityReceiver, and I think I see what the bug is. Here’s the callback we pass toregisterNetworkCallback:When the system invokes one of our callback methods, it passes a particular network that there’s an update on. But then we’re tracking the state of only one network at a time; so whatever network we just had an update on, we remember that and forget whatever we knew about any other network.
Before #443, this worked consistently: the callback was only subscribed to be invoked on a single network at a time, namely the default network. That was a limitation that would be good to fix (which was the motivation for #443); but the code did provide an accurate picture of the state of that one network, which is good enough for many use cases.
After #443, though, the code doesn’t really work in any reliable way. We’re subscribed to updates on all networks, but only remember what happened with the last network that had an update. That means that if, say, the device gains wifi and then loses cellular, we’ll end up thinking there’s no connection, because the cellular connection was the last to update.
In particular I think this means that the code as it currently is will work unreliably even for the motivating use case of #443: if the app-specific wifi network becomes available, but then some other network goes away, we’ll stop thinking there’s a connection at all.
A working version of the feature #443 was meant to implement would probably involve keeping around a data structure with information on all the different networks that are currently available. This probably isn’t super hard, but will require someone to do some work to write it.
If that doesn’t happen, or until that happens, probably the best thing is to revert #443. The library then won’t offer the functionality of giving information about networks other than the default network. But it will again reliably provide what it does offer, which is information about the default network.