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.
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.