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

HTTPAltValidator not correctly triggered with multiple concurrent calls #13

Closed
malcommac opened this issue Feb 16, 2022 · 1 comment
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@malcommac
Copy link
Collaborator

malcommac commented Feb 16, 2022

Bug Report

This bug affect both the 0.9.x (pre-releases) and the new 1.0.0.
The bug avoid HTTPAltValidator to be triggered when multiple concurrent calls are calling the same validator. This happens because numberOfAltRequestExecuted is incremented even when no alt-request is triggered so it reach very fast the limit (maxAltRequestsToExecute).

This check should be moved right before returning the alt call.

open func validate(response: HTTPRawResponse, forRequest request: HTTPRequestProtocol) -> HTTPResponseValidatorResult {
        if let statusCode = response.error?.statusCode, triggerHTTPCodes.contains(statusCode) {
            return .passed
        }
        
        // If error is one of the errors in `triggerHTTPCodes`
        
        // If we reached the maximum number of alternate calls to execute we want to cancel any other attempt.
        if let maxAltRequestsToExecute = maxAltRequestsToExecute,
              numberOfAltRequestExecuted > maxAltRequestsToExecute {
            let error = HTTPError(.maxRetryAttemptsReached)
            return .failWithError(error)
        }
        
        guard let altOperation = requestProvider(request, response) else {
            return .passed // if no retry operation is provided we'll skip and mark the validation as passed
        }

        numberOfAltRequestExecuted += 1
        return .retryAfter(altOperation)
    }
Q A
BC Break yes
Version 0.9.x and 1.0.x
@malcommac malcommac changed the title Fixed for HTTPAltValidator trigger in HTTPAltValidator not triggered with multiple concurrent calls Feb 16, 2022
@malcommac malcommac added the bug Something isn't working label Feb 16, 2022
@malcommac malcommac self-assigned this Feb 16, 2022
@malcommac malcommac added this to the 1.0.1 milestone Feb 16, 2022
@malcommac
Copy link
Collaborator Author

fixed in 0.9.18 - pre-release

@malcommac malcommac changed the title HTTPAltValidator not triggered with multiple concurrent calls HTTPAltValidator not correctly triggered with multiple concurrent calls Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant