From 3069ce01e005b50669e8228eaa7704c8b873842a Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 4 Aug 2015 12:15:15 +0200 Subject: [PATCH] Fix lockup bug on Linux --- probe/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/probe/main.go b/probe/main.go index 6b4e4f979..b1e5864d2 100644 --- a/probe/main.go +++ b/probe/main.go @@ -8,6 +8,7 @@ import ( _ "net/http/pprof" "os" "os/signal" + "runtime" "strconv" "strings" "syscall" @@ -127,14 +128,22 @@ func main() { } if *captureEnabled { + var sniffers int for _, iface := range strings.Split(*captureInterfaces, ",") { source, err := sniff.NewSource(iface) if err != nil { log.Printf("warning: %v", err) continue } + defer source.Close() log.Printf("capturing packets on %s", iface) reporters = append(reporters, sniff.New(hostID, localNets, source, *captureOn, *captureOff)) + sniffers++ + } + // Packet capture can block OS threads on Linux, so we need to provide + // sufficient overhead in GOMAXPROCS. + if have, want := runtime.GOMAXPROCS(-1), (sniffers + 1); have < want { + runtime.GOMAXPROCS(want) } }