mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-21 22:36:39 +00:00
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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user