react-native-firebase
react-native-firebase copied to clipboard
🔥 [🐛] Snapshot Listener accrues delay on iOS - OK on Android
Issue
Hey guys. Running a very standard snapshot listener but running into some weird issues. On Android everything works fine, as soon as I modify a firestore document the snapshot listener triggers, however, on iOS it "accrues" delay. By this I mean that it responds to a change with an increasingly long delay.
- If I wait 5 seconds it triggers immediately
- If I wait 1 minute it takes a couple seconds
- If I wait 5 minutes it can take up to a minute
I'm trying everything to understand what's going on here and I've come across a very bizarre phenomena which may help someone understand what's going on:
If I let the listener sit for a while (5 min) and then I modify a document in the firestore, the snapshot won't trigger for about 1 minute. However, if during that minute I make a very simple firestore read it will "magically" wake up the snapshot listener which will finally trigger as soon as I make that read.
My snapshot listener:
React.useEffect(() => {
navigation.setOptions({ title: ('Standby'),
headerLeft: () => (
<HeaderBackButton onPress={() => goBack()}/>
)});
const unsubscribe = firestore().collection("recordings").where("eventId", "==", eventId)
.onSnapshot(function(snapshot) {
snapshot.docChanges().forEach(function(change) {
console.log('Snapshot trigger!')
if (change.type === "added") {
newRecording(change.doc.data())
}
if (change.type === "modified") {
newTip(change.doc.data())
}
});
});
return () => unsubscribe()
}, [])
My "dummy" read which wakes up the listener:
const fetch = () => {
console.log('This button does nothing - ', dummy)
eventRef.get().then(function (event) {
console.log('Got event data', event.data())
}).catch(function (error) {
console.log("Error getting event document:", error);
});
}
Which I force to happen by clicking this button:
<Button title='Fetch?' onPress={() => fetch()}></Button>
My imports:
import firebase from '@react-native-firebase/app';
import storage from '@react-native-firebase/storage';
import firestore from '@react-native-firebase/firestore'
Project Files
Javascript
Click To Expand
package.json:
{
"name": "RNSoundCaptureApp",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@react-native-community/geolocation": "^2.0.2",
"@react-native-community/masked-view": "^0.1.6",
"@react-native-community/netinfo": "^5.9.6",
"@react-native-firebase/app": "12.2.0",
"@react-native-firebase/auth": "12.2.0",
"@react-native-firebase/firestore": "12.2.0",
"@react-native-firebase/functions": "^12.2.0",
"@react-native-firebase/storage": "12.2.0",
"@react-navigation/bottom-tabs": "^5.0.0",
"@react-navigation/native": "^5.0.0",
"@react-navigation/stack": "^5.0.0",
"@sayem314/react-native-keep-awake": "^1.0.3",
"@stripe/stripe-react-native": "^0.1.4",
"@types/geodesy": "^2.2.0",
"@types/validator": "13.0.0",
"currency-symbol-map": "^4.0.4",
"eslint": "6",
"esm": "^3.2.25",
"geodesy": "^2.2.0",
"lamejs": "^1.2.0",
"prop-types": "^15.7.2",
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-geocoding": "^0.4.0",
"react-native-gesture-handler": "^1.5.6",
"react-native-image-picker": "^2.3.1",
"react-native-maps": "^0.27.1",
"react-native-microphone-stream": "git+ssh://[email protected]:sound-capture/sc-rn-mic-stream.git#develop",
"react-native-permissions": "^2.2.0",
"react-native-progress": "^4.1.2",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "0.6",
"react-native-screens": "^2.0.0-beta.2",
"react-native-sound-player": "0.10.3",
"react-native-version-check": "^3.4.2",
"react-native-webview": "^10.9.2",
"validator": "^13.1.1"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@react-native-community/eslint-config": "^1.1.0",
"@types/jest": "^24.0.18",
"@types/react-native": "^0.60.22",
"@types/react-test-renderer": "16.9.0",
"babel-jest": "^25.1.0",
"jest": "^25.1.0",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "16.13.1",
"typescript": "^3.6.3"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
firebase.json for react-native-firebase v6:
# N/A
iOS
Click To Expand
ios/Podfile:
- [ ] I'm not using Pods
- [x] I'm using Pods and my Podfile looks like:
# N/A
AppDelegate.m:
// N/A
Android
Click To Expand
Have you converted to AndroidX?
- [ ] my application is an AndroidX application?
- [ ] I am using
android/gradle.settingsjetifier=truefor Android compatibility? - [ ] I am using the NPM package
jetifierfor react-native compatibility?
android/build.gradle:
// N/A
android/app/build.gradle:
// N/A
android/settings.gradle:
// N/A
MainApplication.java:
// N/A
AndroidManifest.xml:
<!-- N/A -->
Environment
Click To Expand
react-native info output:
System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Memory: 62.35 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.19.0 - /usr/local/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: 12.0.1 - /usr/bin/javac
Python: 3.7.7 - /usr/local/opt/python/libexec/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.2 => 0.63.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
- Platform that you're experiencing the issue on:
- [x] iOS
- [ ] Android
- [ ] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
react-native-firebaseversion you're using that has this issue:12.2.0
Firebasemodule(s) you're using that has the issue:firestore
- Are you using
TypeScript?Y&^3.6.3
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.
Hi there! With apologies, I don't believe this will be centered in this module, I believe this will be an underlying issue, as we do not handle delays at all, we are more like a mailman delivering the events that the firebase-ios-sdk gives us. If we get an event, we deliver it. If we don't, we don't. My first step if I were you would be to attempt a reproduction using the quickstart here and if you can reproduce it natively, post that on the firebase-ios-sdk repo https://github.com/firebase/quickstart-ios/tree/master/firestore
Hey @mikehardy thanks for the response. I see what you mean and understand that theres only so much you can help with. In an attempt to overcome this I've upgraded all my firebase modules to the latest version (12.2.0) but am still getting the same slowness. Just to recap:
- Only my snapshot listeners are effected by this (all other firestore gets and writes work very fast)
- Only a problem on iOS not Android
- Doing a random get() seems to "wake up" the listener
- The delays get worst over time
- My documents are really light (5 fields with minimal data)
It's such odd and extreme behavior that I'd really hope someone else would have the same issue but I don't see much. It's vaguely similar to this issue that you helped on actually. I guess I'm getting realy desperate here as I can't afford to have my snapshot listener be delayed by more than 10 seconds (which is already so much!). Really any insight onto things I can try here would be extremely welcome.
Thanks!
Using the Quickstart to repro native sdk is really the best path. They run out of the box, I'm guessing it is pretty minimal effort even though it seems like a big tangent. I don't use snapshot listeners personally and haven't seen anyone else with your described experience so I just don't know past that, sorry
OMG I think I figured it out. So stupid. So crazy. I think it's my WiFi. When I build for release and did testing on my phone I had the same issues... until I took it off wifi. Then everything worked exactly as expected. I just connected my laptop to my phone's hot-spot and... sure enough everything works on the emulator too. This was the worst debugging experience ever. Thanks for the help @mikehardy.
FWIW I'm on a Spectrum network and my wifi has been weird (not bad, just weird). For example I get this super bizarre bug with Zoom.
It should be a crime for isps to do anything with packets except prioritize according to your own packet priority marks. Sounds like they are monkeying with the connection somehow
Yeah I'm pretty dumbfounded. Still crazy that it's only a problem on my iOS emulator and not my Android emulator. @mikehardy do you think this should be a bug report on the firebase iOS SDK Github?
Not unless you can knock together a minimum reproducible example based on their quickstart, no. Won't be worth the trouble otherwise, as it won't get attention
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.