Skip to content

Commit

Permalink
Add guard against potentially blocking forever when NumGoroutines is 0
Browse files Browse the repository at this point in the history
Closes #7462

Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
ajm188 committed Feb 7, 2021
1 parent 20e1242 commit d1e07fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/vt/concurrency/error_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (eg ErrorGroup) Wait(cancel context.CancelFunc, errors chan error) *AllErro
responseCounter := 0
rec := &AllErrorRecorder{}

if eg.NumGoroutines < 1 {
return rec
}

for err := range errors {
responseCounter++

Expand Down
34 changes: 34 additions & 0 deletions go/vt/concurrency/error_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package concurrency

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestErrorGroup(t *testing.T) {
t.Run("Wait() returns immediately when NumGoroutines = 0", func(t *testing.T) {
eg := ErrorGroup{
NumGoroutines: 0,
}

rec := eg.Wait(nil, nil)
assert.NoError(t, rec.Error())
})
}

0 comments on commit d1e07fc

Please sign in to comment.