fix(pcap): fix file descriptor error

This commit is contained in:
2025-10-12 13:06:09 +01:00
parent 80632dd1d9
commit a64d6c6bdb
2 changed files with 2 additions and 8 deletions

View File

@@ -31,12 +31,7 @@ func NewPacketCapture(iface, outputPath string) (*PacketCapture, error) {
fileExists = true fileExists = true
} }
var file *os.File file, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if fileExists {
file, err = os.OpenFile(outputPath, os.O_APPEND, 0644)
} else {
file, err = os.Create(outputPath)
}
if err != nil { if err != nil {
handle.Close() handle.Close()
return nil, fmt.Errorf("create/open pcap file: %w", err) return nil, fmt.Errorf("create/open pcap file: %w", err)

View File

@@ -126,6 +126,7 @@ func (r *MeasurementRunner) runQueries(dnsClient client.DNSClient, upstream stri
packetCapture *capture.PacketCapture) error { packetCapture *capture.PacketCapture) error {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := packetCapture.Start(ctx); err != nil { if err := packetCapture.Start(ctx); err != nil {
return err return err
@@ -162,8 +163,6 @@ func (r *MeasurementRunner) runQueries(dnsClient client.DNSClient, upstream stri
} }
} }
cancel()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if err := packetCapture.GetError(); err != nil { if err := packetCapture.GetError(); err != nil {