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

va: use cancels to early-return. #7832

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions va/va.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,13 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
err error
}

subCtx, cancel := context.WithCancel(ctx)
defer cancel()

responses := make(chan *response, remoteVACount)
for _, i := range rand.Perm(remoteVACount) {
go func(rva RemoteVA) {
res, err := rva.PerformValidation(ctx, req)
res, err := rva.PerformValidation(subCtx, req)
responses <- &response{rva.Address, res, err}
}(va.remoteVAs[i])
}
Expand Down Expand Up @@ -507,26 +510,32 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
firstProb = currProb
}

// To respond faster, if we get enough successes or too many failures, we cancel remaining RPCs.
// Finish the loop to collect remaining responses into `failed` so we can rely on having a response
// for every request we made.
if len(passed) >= required {
// Enough successful responses to reach quorum.
return nil
cancel()
}
if len(failed) > va.maxRemoteFailures {
// Too many failed responses to reach quorum.
firstProb.Detail = fmt.Sprintf("During secondary domain validation: %s", firstProb.Detail)
return firstProb
cancel()
}

// If we somehow haven't returned early, we need to break the loop once all
// of the VAs have returned a result.
// Once all the VAs have returned a result, break the loop.
if len(passed)+len(failed) >= remoteVACount {
break
}
}

// This condition should not occur - it indicates the passed/failed counts
// neither met the required threshold nor the maxRemoteFailures threshold.
return probs.ServerInternal("Too few remote PerformValidation RPC results")
if len(passed) >= required {
return nil
} else if len(failed) > va.maxRemoteFailures {
firstProb.Detail = fmt.Sprintf("During secondary domain validation: %s", firstProb.Detail)
return firstProb
} else {
// This condition should not occur - it indicates the passed/failed counts
// neither met the required threshold nor the maxRemoteFailures threshold.
return probs.ServerInternal("Too few remote PerformValidation RPC results")
}
}

// logRemoteResults is called by `processRemoteCAAResults` when the
Expand Down
Loading