Skip to content

Commit a968172

Browse files
committed
fix: goroutine leak when timeout
1 parent d1538f0 commit a968172

File tree

18 files changed

+1059
-1
lines changed

18 files changed

+1059
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/pborman/uuid v1.2.1
2626
github.com/pkg/errors v0.9.1
2727
github.com/stretchr/testify v1.10.0
28+
go.uber.org/goleak v1.3.0
2829
go.uber.org/mock v0.5.0
2930
golang.org/x/net v0.37.0
3031
golang.org/x/sync v0.12.0

pkg/util/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ type TimeoutFunc func() (err error)
404404
// WaitUntilTimeout waits for the exec function to complete or return timeout error
405405
func WaitUntilTimeout(timeout time.Duration, execFunc ExecFunc, timeoutFunc TimeoutFunc) error {
406406
// Create a channel to receive the result of the azcopy exec function
407-
done := make(chan bool)
407+
done := make(chan bool, 1)
408408
var err error
409409

410410
// Start the azcopy exec function in a goroutine

pkg/util/util_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/stretchr/testify/assert"
28+
"go.uber.org/goleak"
2829
"go.uber.org/mock/gomock"
2930
"k8s.io/kubernetes/pkg/volume"
3031
)
@@ -821,6 +822,7 @@ func TestSetVolumeOwnership(t *testing.T) {
821822
}
822823

823824
func TestWaitUntilTimeout(t *testing.T) {
825+
defer goleak.VerifyNone(t)
824826
tests := []struct {
825827
desc string
826828
timeout time.Duration
@@ -847,6 +849,7 @@ func TestWaitUntilTimeout(t *testing.T) {
847849
return nil
848850
},
849851
timeoutFunc: func() error {
852+
time.Sleep(2 * time.Second)
850853
return fmt.Errorf("timeout error")
851854
},
852855
expectedErr: fmt.Errorf("timeout error"),

vendor/go.uber.org/goleak/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.uber.org/goleak/.golangci.yml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.uber.org/goleak/CHANGELOG.md

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.uber.org/goleak/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.uber.org/goleak/Makefile

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.uber.org/goleak/README.md

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.uber.org/goleak/doc.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)