Skip to content

Commit

Permalink
fix random behaviour in executeFilters (#164)
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Chwastek <[email protected]>
  • Loading branch information
hfastek and Kamil Chwastek authored Jan 27, 2023
1 parent 184e939 commit 8869dbf
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions pkg/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func sortInstanceTypeInfo(instanceTypeInfoSlice []*instancetypes.Details) []*ins
// executeFilters accepts a mapping of filter name to filter pairs which are iterated through
// to determine if the instance type matches the filter values.
func (itf Selector) executeFilters(filterToInstanceSpecMapping map[string]filterPair, instanceType string) (bool, error) {
abort := make(chan bool, len(filterToInstanceSpecMapping))
verdict := make(chan bool, len(filterToInstanceSpecMapping) + 1)
errs := make(chan error)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -385,31 +385,29 @@ func (itf Selector) executeFilters(filterToInstanceSpecMapping map[string]filter
errs <- err
}
if !ok {
abort <- true
verdict <- false
}
}
}(ctx, filterName, filter)
}
done := make(chan bool)
go func() {
wg.Wait()
done <- true
verdict <- true
}()
select {
case <-abort:
cancel()
var err error
for {
select {
case e := <-errs:
err = multierr.Append(err, e)
default:
return false, err
}
}
case <-done:

if <-verdict {
return true, nil
}
cancel()
var err error
for {
select {
case e := <-errs:
err = multierr.Append(err, e)
default:
return false, err
}
}
}

func exec(instanceType string, filterName string, filter filterPair) (bool, error) {
Expand Down

0 comments on commit 8869dbf

Please sign in to comment.