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: Fix performRemoteValidation goroutine leak #7727

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions va/va.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,24 @@ func (va *ValidationAuthorityImpl) performRemoteValidation(
response *vapb.ValidationResult
err error
}
results := make(chan *rvaResult, len(va.remoteVAs))

results := make(chan *rvaResult)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

for _, i := range rand.Perm(len(va.remoteVAs)) {
remoteVA := va.remoteVAs[i]
go func(rva RemoteVA, out chan<- *rvaResult) {
res, err := rva.PerformValidation(ctx, req)
out <- &rvaResult{
select {
case out <- &rvaResult{
hostname: rva.Address,
response: res,
err: err,
}:
case <-ctx.Done():
// Context canceled, exit the goroutine.
return
Comment on lines +483 to +486
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend removing this branch. Now that the results chan is buffered to the full length of possible outputs, writing to it (on line 479) is guaranteed not to block. Putting a case <-ctx.Done() in doesn't change anything.

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 added to facilitate early termination of the goroutines, not prevent blocking on the channel.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. I'm saying the goroutine will terminate at the same time even without the case <-ctx.Done(), because the only other thing that's happening here is the channel write, which doesn't block.

}
}(remoteVA, results)
}
Expand Down