fix: remove data race in pcap capture

Capture handle should be closed in the same goroutine with packet
reading.

Fix a spurious error which might appear in `talosctl pcap`.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
This commit is contained in:
Andrey Smirnov 2022-07-20 01:10:59 +04:00
parent 04a45dff28
commit 80444a43d9
No known key found for this signature in database
GPG Key ID: 7B26396447AB6DFD
2 changed files with 5 additions and 1 deletions

View File

@ -101,6 +101,10 @@ e.g. by excluding packets with the port 50000.
go func() {
defer wg.Done()
for err := range errCh {
if client.StatusCode(err) == codes.DeadlineExceeded {
continue
}
fmt.Fprintln(os.Stderr, err.Error())
}
}()

View File

@ -2120,6 +2120,7 @@ func (s *Server) PacketCapture(in *machine.PacketCaptureRequest, srv machine.Mac
go func() {
defer pw.Close() //nolint:errcheck
defer handle.Close()
pcapw := pcapgo.NewWriterNanos(pw)
@ -2141,7 +2142,6 @@ func (s *Server) PacketCapture(in *machine.PacketCaptureRequest, srv machine.Mac
}
}()
defer handle.Close()
defer pr.Close() //nolint:errcheck
ctx, cancel := context.WithCancel(srv.Context())