Fixed potential KVO crasher for URL Session Task delegates #3718
Conversation
Adding self as observer in init and removing self as observer in dealloc is the best way to ensure a proper KVO implementation.
The dispatching on main thread was introduced in 920e266 in order to fix #2053. It was not a proper fix but rather a lucky coincidence. This kind of KVO error must be fixed by ensuring that observer are properly registered and unregistered, not by dispatching some random method on the main thread. It is very important not to dispatch async session invalidation code because it is called in unit tests from the `tearDown` method. At that point, there’s no active runloop, so the session invalidation would not happen immediately but when running the next asynchronous unit test, i.e. when the `waitForExpectationsWithCommonTimeoutUsingHandler:` method is called. This commit, in conjunction with d869571 fixes #3710.
Current coverage is 87.81% (diff: 86.66%)@@ master #3718 diff @@
==========================================
Files 44 44
Lines 6093 6064 -29
Methods 1084 1079 -5
Messages 0 0
Branches 406 406
==========================================
- Hits 5345 5325 -20
+ Misses 745 736 -9
Partials 3 3
|
|
This is great work @0xced! I was actually going down the same rabbit hole last week before my vacation, so I agree with all of your assessment here! I'm verifying these changes locally as well right now. Will merge soon assuming I find no other issues. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please see both commit comments for a full explanation.