Skip to content

Commit 10c1ef3

Browse files
nader-ziadaaramprice
authored andcommitted
fix linter issue about lostcancel
golangci-lint starting with version v1.62.0 gives the following error: lostcancel: the cancel function is not used on all paths (possible context leak) if a func returns without calling the cancel() func
1 parent 69fefaa commit 10c1ef3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pcap/pcap.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ func (p PcapRunnerImpl) Run(result boshdir.SSHResult, username string, argv stri
5454
done := make(chan struct{})
5555

5656
wg := &sync.WaitGroup{}
57+
var err error
5758

5859
ctx, cancel := context.WithCancelCause(context.Background())
60+
defer cancel(err)
5961

6062
clientFactory := boshssh.NewClientFactory(p.logger)
6163

@@ -89,10 +91,11 @@ func (p PcapRunnerImpl) Run(result boshdir.SSHResult, username string, argv stri
8991
}
9092

9193
if runningCaptures == 0 {
92-
return fmt.Errorf("starting of all pcap captures failed")
94+
err = errors.New("starting of all pcap captures failed")
95+
return err
9396
}
9497

95-
err := writePacketsToFile(opts.SnapLength, opts.Output, packetCs, p.ui)
98+
err = writePacketsToFile(opts.SnapLength, opts.Output, packetCs, p.ui)
9699
if err != nil {
97100
return fmt.Errorf("write to output file failed: %w", err)
98101
}

0 commit comments

Comments
 (0)