Automattic / Gravatar-SDK-iOS

Gravatar SDK is a Swift library that allows you to integrate Gravatar features into your own iOS applications.
https://gravatar.com
Mozilla Public License 2.0
36 stars 1 forks source link

Remove the task from the cache when cancelled #276

Closed pinarol closed 3 months ago

pinarol commented 3 months ago

Closes #

Description

I bumped into a bug while testing the WP side. There, the existing download is cancelled before each download attempt. Even though it's not necessary to do that it should work fine(especially after the CacheEntry.inProgress option no one needs to worry about multiple requests for the same URL but that's a separate topic).

Anyway, I come across with a screen where the avatar remained empty and all download attempts resulted in "cancelled". I think it can be because we don't remove the task from the cache when cancelling it, so next time we try to download the same image it tries to await a cancelled task, which then results in a cancelled error to be thrown. But it is not easy to reproduce and I was able to repro the issue only in post revisions page. (somehow that page attempts to download the image multiple times even if there's only 1 cell, I guess the tableview is reloaded multiple times).

Testing Steps

Let's first try to reproduce the issue:

Checkout this PR https://github.com/wordpress-mobile/WordPress-iOS/pull/23320 Login to Jetpack app Go to Posts > Open one of your posts Use the ... on the top to open the menu Tap on the Revisions item (If you don't see Revisions there it means you didn't edit the file yet. In that case edit and publish the post. Then check again.)

The avatar remains empty. (I am not sure how consistent you can repro the issue though. I suspect that it's a race condition)

Now point Gravatar SDK to the latest commit from this PR and test it again. The avatar should load fine.