Fix a race condition during progressive animation load in SDAnimatedImageView #2435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the coder was updated, currentData may not be the same instance as previousdData. We should check the that current data is appended by previous data
New Pull Request Checklist
I have read and understood the CONTRIBUTING guide
I have read the Documentation
I have searched for a similar pull request in the project and found none
I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)
I have added the required tests to prove the fix/feature I am adding
I have updated the documentation (if necessary)
I have run the tests and they pass
I have run the lint and it passes (
pod lib lint
)This merge request fixes / reffers to the following issues: ...
Pull Request Description
This PR fix a race condition, for that 5.0 SDAnimatedImageView progressive animated image rendering. (See Animatied Image - Rendering)
Because of current implementation detail of
SDAnimatedImage
architecture, eachSDAnimatedImage
hold a decoder, theSDAnimatedImage.animatedImageData
is just a proxy to call decoder's data). For progressive animation support, each progressive image during same request is created with the request-level decoder for performance. Here is a race condition that during progressive download, thepreviousData
may be not the same ascurrentData
instance. Because they share one coder, the coder can be updated just at the two retrive function call. So it will cause we reset the progressive decoding status.And current implementation is hard-coded, to assume that
SDAnimatedImage
always return the same data, it's not correct. The correct judgement, in natural language, is thatThe new data should be appened from the old data with new bytes
. For code, we should check that new data contains hole subdata of old data, and they start with the same begining bytes.This bug can actually be reproduced with our 5.x demo. You can limit your network speed to 512KB, go push and pop the
Image#2
several times (Clear cache each time it loads finished). You'll have a rare chance to see that the current playing animation is reset to the 0 frame.