From 9208e08bf3eaab9d276c53af6db5e9f7d141b4fb Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 20 Sep 2019 14:31:07 +0000 Subject: [PATCH] Change dns snooper timeout to avoid spinning in pcap The previous code seems to be relying on a 64-bit to 32-bit conversion working in a certain way; when gopacket was changed to cast the value explicitly it starts returning immeditely from pcap. --- probe/endpoint/dns_snooper.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/probe/endpoint/dns_snooper.go b/probe/endpoint/dns_snooper.go index c1151fb09..e3058ac19 100644 --- a/probe/endpoint/dns_snooper.go +++ b/probe/endpoint/dns_snooper.go @@ -8,7 +8,6 @@ import ( "bytes" "encoding/binary" "fmt" - "math" "sync" "time" @@ -60,9 +59,10 @@ func newPcapHandle() (*pcap.Handle, error) { return nil, err } defer inactive.CleanUp() - // pcap timeout blackmagic copied from Weave Net to reduce CPU consumption + // Set a long timeout because "pcap.BlockForever" actually spins on a 10ms timeout // see https://github.com/weaveworks/weave/commit/025315363d5ea8b8265f1b3ea800f24df2be51a4 - if err = inactive.SetTimeout(time.Duration(math.MaxInt64)); err != nil { + // (note the value in microseconds has to fit in a 32-bit signed int) + if err = inactive.SetTimeout(time.Minute * 30); err != nil { return nil, err } if err = inactive.SetImmediateMode(true); err != nil {