-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Add number_of_retries option to set() so that it fails when offline. #520
Comments
Thanks for the report. This is currently expected behavior. It is common to experience temporary network glitches (even while your app is "online") and so Firestore will transparently retry the write operation until it completes. We do this regardless of whether persistence is enabled. Enabling persistence will additionally persist the write operation in IndexedDb so if you close and re-open the app (or refresh the page in a normal web app), the write operation will be restored and we'll again attempt to send it to the backend. Note that get() calls behave differently since the user is presumably waiting for the data to be returned and so waiting indefinitely while offline is not suitable. So get() calls should fail (and call your catch handler) if the client is offline. Can you explain your use case a bit more and what UX you are trying to provide? I wonder if failing the write is actually what you want or if some other indicator of "offline-ness" would be more suitable. Thanks! |
This exactly what we looking for... to achieve a better user experience in our targeted apps we should give user feedback of successful save operations..
as you can see from code... I would prefer add some options to control the behaviour on set(), update() and maybe batch.commit(); giving us more control THANKS |
The "save indicator" is exactly how we expect people to deal with this sort of situation and provide an optimal user experience, so they can provide feedback to the user that the write hasn't completed yet. You could optionally also have a timer so that if the save indicator doesn't go away after some time period (e.g. 10 seconds) you show a more aggressive notification (e.g. "WARNING: Your writes have not yet been committed to the server. Please ensure your device is online else you risk losing your work.") If this isn't suitable for your case, I'd be curious to hear more about your use case including under what circumstances you would want the write to fail given that networks are inherently unreliable (temporary network issues are the norm, especially on mobile devices). Would you want an immediate failure? Or would you want a certain number of retries or a timeout or something? Thanks! |
@mikelehen adding options to control the behaviour of update retries will enable us to manage the UX.. the amazing option i wish we can have i hope that i explain the cases which i think any developer looking for. Thanks. |
Do you evaluate the need of number_of_retries options to be added?? I don't know how explain, but small scenario.. i think we need more control for the save operations.. Thanks.. |
Dear @mikelehen Do we have any chance to solve this problem? Thanks |
We're interested in exploring features along these lines, though we want to capture more use cases before deciding what the API should look like. In particular I'm wary of adding timeouts and retry options since this is largely contrary to what the Firebase SDK is attempting to provide. It's explicitly designed to handle offline and network interruptions, etc. rather than just being a wrapper over the REST API. I've added your feedback to an internal tracking bug, but we're probably going to hold off on implementing any changes until we get more feedback. In the meantime if the REST API seems like a better fit to you, you're more than welcome to use it. It will give you full control over retries and timeouts, etc. at the expense of seamless handling for offline / network interruptions. |
I hope that you push this case to more firebase users and get a feedback. Thanks for your following up.. |
@mohshraim Based on having used Firestore for a while longer, do you still feel this is something you would find useful? |
@mikelehen I think the feature i request in the Subject is not that useful as you mentioned for my current project as i use persistence, and we will start another project soon that disable the persistence which i think not having this feature will lead to bug on our project when user offline. Will explain two scenario, one exist and the second for our next project. ** First Scenario with enable persistence. **
** Second Scenario with Disable persistence. **
Sorry for long description but i have to explain in details.. |
Thanks @mohshraim! Can you explain what the "cache success" promise is for? When you do a set() operation, it'll always be committed to the cache immediately, so I'm thinking it doesn't really make sense to return a Promise for that. Our current recommendation for the second case (whether you have persistence enabled or not) is to just do the set(), and then use the hasPendingWrites metadata to show some UI indicating it hasn't been committed to the server yet, e.g. "Saving... Please make sure you are online." That way the user doesn't have to wait 10-15 seconds to know if it's working or have to hit save multiple times, etc. But we can consider adding a timeout in the future. It sounds like that's the mechanism you would prefer. Thanks again for the feedback. |
There is always a chance for Error while saving on IndexedDB one of them 939. and as firestore sdk on this case -as sample- if error occur when we save sdk doesn't return error,, For previous; we can't rely that each save will successfully committed to the cache.. so as mentioned before we add listener to doc before call save on SDK and keep listen for this listener if any change occur we make it as (cache success saved). The second case, as your suggestion then we have also to add listener for doc to make sure its saved, so FR for timeout will be amazing... Thanks for your follow up |
@mikelehen
Thanks |
@mohshraim Thanks. For #939, I think this is sort of outside the scope of this conversation because the SDK is hitting an internal error due to a bug in Chrome. So the entire SDK ends up in a bad state, and having a "cache success" Promise doesn't solve that. The "called with invalid data" error is intentionally a synchronous exception (rather than returning a rejected Promise). It indicates a programming error and so we don't expect developers to be programmatically catching it (but you can with |
@mikelehen I can enclose my (set,update) statements with |
For the purposes of writing your app, you can safely assume so, yes. Technically writes to IndexedDb are asynchronous and so it's possible the client could crash or the user could immediately close the app or something, preventing our write from completing locally. But realistically, the IndexedDb operation should complete in under 10s of milliseconds and so it will be written locally before the user has any chance to do anything. So we 100% recommend that people just "set it and forget it". If you need a stronger guarantee than that, then you probably want to wait for it to be written to the server anyway and should just wait for the Promise completion. |
+1 to this feature. Our use case with some major simplificationsWe use Firestore to maintain state in our app to see if an user have a specific resource open or not. This is done by having the user update a document every x seconds with a timestamp. If the user goes offline they are still able to view and update the resource and we save the changes locally (we do not use Firestore due to document size limitations). With the current retry until successful strategy the user could have closed the resource while offline and once they come online they will send unnecessary updates of their state that is no longer true. Therefore we would very much like an option to set max retries, a timeout, or perhaps cancel a pending set/update. |
In my intuition, I expect both So, If I was an implementer of the API, I would just disable retries of both read and write operations if apps are offline and persistence is enabled as even written changes are eventually synchronized with remote stores anyway. Another point of discussion is if IndexDB persistence should behave like a cache or a local store. Currently, it behaves like a cache as its write operations never complete offline. But I think it should behave like a local store ... |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Using firestore on web Javascript, i need to work only if user connected to internet so i didn't enable
persistence. --> firebase.firestore().enablePersistence() ...
if i disconnect the network then add a new item to my DB collection the console show many connection error from firestore but wait until i reconnect and then confirm the success of add operation...
expected behaviour; as i didnt enable the persistence feature the (set or update ) should fire the catch and notify me for connection..
maybe it can be as feature request to add options to wait for reconnect or through error on offline, adding this will provide more control to application if we want to enablePersistence..
thanks
The text was updated successfully, but these errors were encountered: