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:
parent
04a45dff28
commit
80444a43d9
@ -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())
|
||||
}
|
||||
}()
|
||||
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user