From 4795ba58077c240bd3555ac73903420c36127880 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 4 Aug 2020 14:36:27 +0000 Subject: [PATCH] Show stack-trace from panic in weave-npc Rather than exiting silently, fetch the stack trace and print that for the user to understand what happened. Exit via existing fatal-error code. --- prog/weave-npc/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/prog/weave-npc/main.go b/prog/weave-npc/main.go index 79909a24..ba307bb5 100644 --- a/prog/weave-npc/main.go +++ b/prog/weave-npc/main.go @@ -2,8 +2,10 @@ package main import ( "context" + "fmt" "os" "os/signal" + goruntime "runtime" "syscall" "github.com/coreos/go-iptables/iptables" @@ -218,7 +220,9 @@ func hCtx() context.Context { func stopOnPanicRecover() { if r := recover(); r != nil { - os.Exit(1) + buf := make([]byte, 1<<20) + stacklen := goruntime.Stack(buf, false) + handleFatal(fmt.Errorf("panic: %v \n%s", r, buf[:stacklen])) } }