Skip to content

Commit abc4a34

Browse files
ctrlaltdel121austinvazquez
authored andcommitted
stop tickers in defer to prevent leak
Signed-off-by: Jeremy Williams <[email protected]>
1 parent d4e13a5 commit abc4a34

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

internal/vm/vsock.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const (
3838
// path and port. It will retry connect attempts if a temporary error is encountered (up
3939
// to a fixed timeout) or the provided request is canceled.
4040
func VSockDial(ctx context.Context, logger *logrus.Entry, udsPath string, port uint32) (net.Conn, error) {
41-
tickerCh := time.NewTicker(vsockRetryInterval).C
41+
ticker := time.NewTicker(vsockRetryInterval)
42+
defer ticker.Stop()
43+
tickerCh := ticker.C
4244
var attemptCount int
4345
for {
4446
attemptCount++
@@ -92,7 +94,9 @@ func (l vsockListener) Accept() (net.Conn, error) {
9294
defer cancel()
9395

9496
var attemptCount int
95-
tickerCh := time.NewTicker(vsockRetryInterval).C
97+
ticker := time.NewTicker(vsockRetryInterval)
98+
defer ticker.Stop()
99+
tickerCh := ticker.C
96100
for {
97101
attemptCount++
98102
logger := l.logger.WithField("attempt", attemptCount)

0 commit comments

Comments
 (0)