Skip to content

Commit 8379366

Browse files
committed
fix: goroutine leak when timeout
1 parent 595bb80 commit 8379366

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
@@ -27,6 +27,7 @@ require (
2727
github.com/onsi/gomega v1.36.2
2828
github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021
2929
github.com/stretchr/testify v1.10.0
30+
go.uber.org/goleak v1.3.0
3031
go.uber.org/mock v0.5.0
3132
golang.org/x/net v0.37.0
3233
golang.org/x/sys v0.31.0

pkg/util/util.go

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

223223
// Start exec function in a goroutine

pkg/util/util_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323
"time"
2424

25+
"go.uber.org/goleak"
2526
gomock "go.uber.org/mock/gomock"
2627
)
2728

@@ -351,6 +352,7 @@ func TestParseAzcopyJobShow(t *testing.T) {
351352
}
352353

353354
func TestWaitUntilTimeout(t *testing.T) {
355+
defer goleak.VerifyNone(t)
354356
tests := []struct {
355357
desc string
356358
timeout time.Duration
@@ -377,6 +379,7 @@ func TestWaitUntilTimeout(t *testing.T) {
377379
return nil
378380
},
379381
timeoutFunc: func() error {
382+
time.Sleep(2 * time.Second)
380383
return fmt.Errorf("timeout error")
381384
},
382385
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)