[9.x] Fix Http Client throw boolean parameter of retry method
#41762
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.
Issue
According to PR #40079 and the documentation, the
throwparameter of theretrymethod can be used to not throw an exception when all retries have been attempted:This is currently not the case, because when
throw: false, then it does not attempt any of the retries. It just throws the exception of the first attempt. This is caused by the following if-statement:This issue has also been reported by others: #41601.
Solution
To fix this, we could do the following:
The problem with this approach is when the
retryWhenCallbackclosure returns false (which means that it should not retry) and thethrowparameter is false, then an exception is still thrown.To fix that, we must call the
retryWhenCallbackbefore we throw any exception based on a response.We are almost there. The last issue we now have is when
retryThrowboolean parameter is false andretryWhenCallbackclosure returns false for a certain exception, then it will still retry. This can be fixed by remembering the result of theretryWhenCallbackclosure and using it in thewhenclosure of the globalretryhelper method:I added the necessary tests for all these possibilities