firebase-js-sdk
firebase-js-sdk copied to clipboard
Disabling of experimentalAutoDetectLongPolling due to unnecessary fallback
Operating System
Windows 10/11 latest (and probably all others)
Browser Version
Chrome/Edge latest (and probably all others)
Firebase SDK Version
10.4.0 (probably all down to 9.22)
Firebase SDK Product:
Firestore
Describe your project's tooling
Angular via nx and esbuild
Describe the problem
You declare that users disabling experimentalAutoDetectLongPolling should report it as a bug and describe why in the docs, and I currently do that.... I have no issues with it, except that in my scenario it seems to often fallback to longPolling unnecessary. This is probably due to me disabling/enabling network on visibilitychange, to make all platforms (ios/windows/android) behave the same way, and limit network traffic... This works fine, except for the fallback to longPolling sometimes, so I guess me enabling/disabling network is interfering with the logic for detecting a buffering proxy...
Steps and code to reproduce issue
disable/enable network often and observer traffic in devtools...
I also observe that http3 is used, which multiplexes requests and run on udp. Is buffering proxies common for this transport?
Hi @atsjo ,
Thank you for filing this ticket. Base on your description, it seems like experimentalAutoDetectLongPolling
doesn't fit your use case. You can try to turn on experimentalAutoDetectLongPolling
when your app enables network, and disable it when your app disable the network.
I set this in initializeFirestore, which is only called once at startup. Can this setting be changed other than in initializeFirestore?
I just disable experimentalAutoDetectLongPolling for now, assuming buffering proxies will not be an issue anymore with http3 (or for my customers)
Hi @atsjo , could you please provide more context regards of the reason why you want to set it during runtime? Is it because you want to change this setting together with the network setting?
It was what you suggested above; to enable/disable it together with enabling/disabling network. But I don't really want such a solution, I would rather that your experimentalAutoDetectLongPolling algorithm supports my scenario, where I often disable and enable network.
I could disconnect all listeners and reconnect, instead of enabling/disabling network on every visibilitychange. Maybe that would work better with your algorithm, but I have several listeners, and it would lead to less reusable and more complicated code, and I would also assume disabling/enabling network is more efficient.
I also noted that my connection uses http3, which is multiplexed and transfers via udp. When that transport is used, my assumption is that buffering proxies is not normal anyways. I would think buffering proxies is more of a problem with http1.1, or maybe http2 since it still uses tcp. I could be wrong on that point, but if buffering proxies is not a scenario with this transport, your algorithm could detect http3 is used and not even consider fallback with that....
Hi @atsjo ,
LongPolling
is a feature auto detected and enabled by the backend. In cases of disable the network
won't trigger LongPolling
. Could you please share with us how you observed the LongPolling
is enabled when the network is not available?
Hey @atsjo. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
I never said LongPolling is enabled while network is disabled... I said that when disabling/enabling network the LongPolling is often enabled un-necessary, as it seems to interfere with your auto-detect algorithm... I can observe this in devtools, as stated above... To be clear: If you disable network, and then enable again, your algorithm often mistakes this for network problems and auto-enables LongPolling....
Hi @atsjo ,
I talked to the web channel team, in theory, if the app disables the network, then it would quite possibly affect the response timing, which might make the algorithm think streaming is not enabled, and hence switch to long polling.
However, we cannot reproduce this scenario, it would be helpful if we can get a repo app to tell how frequent the app disable the network and how frequent the long polling happens.
Again, thank you for letting us know about this!
I enable/disable on visibilitychange... you can call function below in a web app and switch tabs or hide/show window... Almost immediately you can see the data traffic switching to long polling. I observe this when I open or close snapshot listeners after page has been hidden and then made visible again, usually after the first time... I have 3 listeners active throughout the app lifetime, and one I open/close on viewing different data....
function activityMonitor(fs: Firestore) {
// ios stops all activity when switching away from app immediately
// android keeps running in background until app frozen
// windows keeps running in background forever (if pc not sleeps)
// this method makes all os behave the same, and prohibits unnecessary data reads
document.addEventListener('visibilitychange', async () => {
if (!document.hidden) {
await enableNetwork(fs);
} else {
await waitForPendingWrites(fs);
disableNetwork(fs);
}
});
}
The version I am using has more error handling and also handles complete re-connects when hidden for > 30 min, but I have not experienced any problem with this approach, except for fallback to long polling. Therefore I have disabled auto-detect...
Thank you for reporting again, we are going to investigate the issue (internal tracking ticket: b/326640653)