diff --git a/pcap/loader.go b/pcap/loader.go index bfc23fe3..95746dfe 100644 --- a/pcap/loader.go +++ b/pcap/loader.go @@ -1359,6 +1359,15 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb //====================================================================== + closedPipe := false + closePipe := func() { + if !closedPipe { + fifoPipeWriter.Close() + fifoPipeReader.Close() + closedPipe = true + } + } + if p.ReadingFromFifo() { // PcapPsml will be nil if here @@ -1378,8 +1387,7 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb // is used as stdin for the psml command, which also runs in this // goroutine. defer func() { - fifoPipeWriter.Close() - fifoPipeReader.Close() + closePipe() }() // wrap the read end of the pipe with a Read() function that counts @@ -1425,6 +1433,10 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb if err != nil { log.Infof("Did not kill tshark psml process: %v", err) } + + if p.ReadingFromFifo() { + closePipe() + } } loop: