Skip to content
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

Fix the race condition when user cancel the network loading will not trigger the completion block #3142

Merged

Conversation

dreampiggy
Copy link
Contributor

@dreampiggy dreampiggy commented Dec 24, 2020

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 / refers to the following issues: #3141

Pull Request Description

This close #3141

Now we do not relay on URLSession delegate timing, directly callback when cancelled.

…trigger the completion block.

Now we do not relay on URLSession delegate timing, directly callback when cancelled.
self.dataTask = nil;
// Provide the same userInfo as URLSession if network is cancelled
// Don't relay on `URLSession:task:didCompleteWithError:` delegate callback because it may delay
[self callCompletionBlocksWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:@{NSLocalizedDescriptionKey: @"cancelled", NSURLErrorFailingURLErrorKey: self.request.URL, NSURLErrorFailingURLStringErrorKey: self.request.URL.absoluteString}]];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just return the same SDWebImageErrorDomain.SDWebImageErrorCancelled as other cancel timing cases ?

I don't knwo whether this change is suitable for most cases. @Insofan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change this into the SDWebImageErrorDomain.SDWebImageErrorCancelled, which pass the unit test.
This design is the same as Kingfisher.

@codecov
Copy link

codecov bot commented Dec 25, 2020

Codecov Report

Merging #3142 (d8961a3) into master (cd2bcaa) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3142      +/-   ##
==========================================
+ Coverage   83.38%   83.41%   +0.02%     
==========================================
  Files          70       70              
  Lines        7674     7675       +1     
==========================================
+ Hits         6399     6402       +3     
+ Misses       1275     1273       -2     
Flag Coverage Δ
ios 83.35% <100.00%> (+0.20%) ⬆️
macos 83.09% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
SDWebImage/Core/SDWebImageDownloaderOperation.m 92.66% <100.00%> (+0.31%) ⬆️
SDWebImage/Core/SDAnimatedImagePlayer.m 90.43% <0.00%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a17674...d8961a3. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completion isn't called when cancel performed async for the second app launch
1 participant