-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Ensure all the session delegate completionHandler called #2197
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
Ensure all the session delegate completionHandler called #2197
Conversation
4e59d0b
to
ead067f
Compare
Codecov Report
@@ Coverage Diff @@
## master #2197 +/- ##
==========================================
- Coverage 78.59% 78.38% -0.22%
==========================================
Files 36 36
Lines 3635 3641 +6
Branches 322 335 +13
==========================================
- Hits 2857 2854 -3
- Misses 756 765 +9
Partials 22 22
Continue to review full report at Codecov.
|
08ac888
to
7f91504
Compare
…k when response error code below iOS 10
7f91504
to
9080afd
Compare
} else { | ||
NSUInteger code = ((NSHTTPURLResponse *)response).statusCode; |
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.
Even through the status code in invalid. We should also store the actual response
and post the notification to let user decide the action. Current implementation contains bug.
And also, for 304, it should not directly call cancelInternal
, which will cause the completion block not been called at all. Because cancelInternal
remove all the callback blocks.
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.
👍 we should read the Apple docs more often i think 😛
This also fix the leak when response error code below iOS 10
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: #1953 #1305 #1597
Pull Request Description
Our usage to let
SDWebImageDownloader
to passURLSessionDelegate
to the operation seems a wrong design. It's because that sometimes, theSDWebImageDownloaderOperation
will be a nil. Because in Apple's doc about URLSession life cycle. It does not means thatdidCompleteWithError:
is the final call. But at that time we already removed theSDWebImageDownloaderOperation
from the operation queue. So some of delegate methods will not do the correct way like the URLSession behavior, especially some delegate which contains acompletionBlock
. If you not call that, the URLSession will mass up.Currently we do not totally change something, but we should add a protect. If the
SDWebImageDownloaderOperation
is nil, we just use the default behavior in the documentation from Apple.So for #1953, I found the reason. By the time
URLSession:dataTask:willCacheResponse:completionHandler:
is called when the server response a 404 error, theSDWebImageDownloaderOperation
is already become nil, so this will cause memory leak below iOS 10. Actually Apple already warn you in the doc