fix(pcap): fix file descriptor error
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user