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

Bugfix - Cancellation Loop #2778

Merged
merged 3 commits into from Apr 1, 2019
Merged

Bugfix - Cancellation Loop #2778

merged 3 commits into from Apr 1, 2019

Conversation

cnoon
Copy link
Member

@cnoon cnoon commented Mar 30, 2019

This PR fixes an issue in the response serialization retry logic where calling cancel and a few other APIs would result in the response serializers running again.

Goals ⚽

Fix the issue where calling request.cancel() inside response serializer would result in the response serializer running again.

Implementation Details 🚧

I should have realized this when I was building it, but it came up when moving our networking library onto AF5 and running the test suite over it. When we finish running all the response serializers and determine that we do not need to retry the request, we then execute all the response serializer completions sequentially. However, we don't exactly know what are in those completions. Therefore, we have to assume the worst and that they call back into the request to possibly do things like request.cancel(). I actually had a few unit tests doing this and found some dragons.

Solution is to clear out all the response serializers and completions from the mutable state prior to actually executing the completions. This is how the logic should have been implemented in the beginning.

Testing Details 🔍

I added a test that fails without this change demonstrating the issue.

Copy link
Member Author

@cnoon cnoon left a comment

Choose a reason for hiding this comment

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

Need to make one change yet.

Source/Request.swift Outdated Show resolved Hide resolved
@@ -1104,7 +1104,6 @@
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
English,
Copy link
Member Author

Choose a reason for hiding this comment

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

This was an issue Xcode caught and wanted to fix so I made the change.

Copy link
Contributor

@jshier jshier left a comment

Choose a reason for hiding this comment

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

Makes sense, but I have some questions about a longer term fix and the testing delay.

Tests/SessionTests.swift Show resolved Hide resolved
Tests/SessionTests.swift Show resolved Hide resolved
@cnoon cnoon merged commit 4df5912 into master Apr 1, 2019
@cnoon cnoon deleted the bugfix/cancellation-loop branch April 1, 2019 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants