-
Notifications
You must be signed in to change notification settings - Fork 58
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
Adding retry feature to mobile apiFetch handler #1686
Conversation
On it! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test this on WP-IOS main app and it's working correctly!
I'm not sure how effective this would be. I think the underlying problem is that Gutenberg would never make a second attempt, rather than needing a retry system on the API layer. With this, if a request fails it will retry 20 times every two seconds, so if you're offline when this starts, and don't get back online within 40 seconds, we're back to where we started. I think the changes we need should happen at the store level, so it doesn't give up on resolving the first time it fails. Also, this is only OK now because we're discarding everything except If we want to implement a network-level retry, I'd probably integrate it with reachability and/or use an incremental delay (like we do on PingHubManager, although that's for establishing a connection). As a side note, we probably should update our fetch handler to behave like
I see some other middleware that relies on having access to the response status as well, so it might bite us in the future. |
Thank you @koke for your comment!
I agree with that! That's where I first started experimenting. But the current architecture made it quite challenging (from what I understood). @youknowriad proposed a middleware based solution. This is not a middleware but close. And probably the same problems we have with this approach, we will have with a middleware on apiFetch. I still think that a store level solution is the best option, but that probably will take more people involved and (maybe?) quite bigger changes.
That sounds like a great improvement to what is proposed here! Indeed 40 seconds of retrying might not be enough on many cases. Ideally we will still cover unstable or intermittent connectivity and timeouts. |
c566ac0
to
a5e9eea
Compare
I have pushed the Android side work and opened related PRs for WPAndroid and FluxC. PR description has also been updated to reflect that. In addition, I also merged in the latest from |
Added an extra delay on every retry cycle. Now it will simply start with 1 second delay, and adding one second on every retry. I think this is enough for this first stage but always open to suggestions. Also returning the error object directly in case we encounter an error code between 400 and 600, instead of rejecting. |
Updated WPiOS and WPAndroid with the latest commit. |
@mchowning would you mind reviewing the latest changes? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
On Android (am not able to test it on iOS as it seems that, at least on the v1.22.0 release branches, the WPiOS Media Library won't allow selecting an image while offline), I see an empty/white box in the image block. I wonder if we can improve the UX here and display a better icon and/or message about the problem (no connectivity, though we should be able to put a version of the image, the one the media library has localy?). Can you open a ticket if there's none already @mchowning ? |
👋 @designsimply ! The image size options were still behind a dev flag in 14.2 (which uses Gutenberg-Mobile 1.22.1 ), so they would have been hidden in release/beta builds. We have changed that for the Gutenberg-Mobile 1.23.0 release, so you should start seeing those image size options in the 14.3 release builds. |
👋 @hypest ! First of all, let's just pretend that responding to your (now 14-day old) comment didn't completely slip my mind. 😞 In testing the failure to download scenario I'm not seeing the behavior you are describing. In both the current Google Store beta build and 1.23 builds (both release and debug), I'm seeing the following when I select an image in my media library while in airplane mode. Do you have any idea what we might be doing differently? Although the UX I'm seeing certainly isn't as good as showing the thumbnail we had downloaded for the media library, it's a lot better than what you were seeing. |
This PR is a simple native-only solution to retry networking calls when they fail with unknown errors. Fixing point 2 of #1593 .
The idea is to catch the error before it returns to the caller, and retrying it if the error is unknown.
There are many kind of errors (both 4xx and 5xx) and we probably don't want to retry, so I decided to go simplistic and focus on caching the most common errors on mobile, that is no internet connection or time out for bad connectivity.
This approach has the following problems (with our only networking call so far [image object] as an example). Consider this scenario:
I think this is still better than never retrying anything, but it's also not the ideal.
The values I have chosen out of trial and error:
Not big feelings about those, but it seemed good enough to not send requests too often, and keep retrying for a decent amount of time.
Android side work left to do
UPDATE: Android side has been added
For this to work, the error returned from the parent apps needs to include the HTTP Status code. WPiOS needed a small change allow that.I noticed that WPAndroid doesn't return status code either, so we will need a fix for this on there too. @mchowning could you take a look at it?To test:
PR submission checklist:
RELEASE-NOTES.txt
if necessary.