From b2bce3858d923488493e6f76eafc63563ae9f680 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Thu, 25 Jan 2024 02:32:20 +0900 Subject: [PATCH] gh-494 In any panic, we need to gracefully exit and unload eBPF at the min --- loxinet/dpebpf_linux.go | 2 +- loxinet/loxinet.go | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/loxinet/dpebpf_linux.go b/loxinet/dpebpf_linux.go index 82c89f9d..b0313359 100644 --- a/loxinet/dpebpf_linux.go +++ b/loxinet/dpebpf_linux.go @@ -317,7 +317,7 @@ func (e *DpEbpfH) DpEbpfUnInit() { e.ToFinCh[i] <- 1 } - tk.LogIt(tk.LogInfo, "ebpf uninit \n") + tk.LogIt(tk.LogInfo, "ebpf uninit : %s\n", debug.Stack()) // Make sure to unload eBPF programs ifList, err := net.Interfaces() diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index 29e45aed..5c06ceaf 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -193,17 +193,6 @@ func loxiNetInit() { logLevel := LogString2Level(opts.Opts.LogLevel) mh.logger = tk.LogItInit(logfile, logLevel, true) - // Stack trace logger - defer func() { - if e := recover(); e != nil { - tk.LogIt(tk.LogCritical, "%s: %s", e, debug.Stack()) - } - if mh.dp != nil { - mh.dp.DpHooks.DpEbpfUnInit() - } - os.Exit(1) - }() - // It is important to make sure loxilb's eBPF filesystem // is in place and mounted to make sure maps are pinned properly if !FileExists(BpfFsCheckFile) { @@ -327,6 +316,16 @@ func loxiNetInit() { // loxiNetRun - This routine will not return func loxiNetRun() { + // Stack trace logger + defer func() { + if e := recover(); e != nil { + tk.LogIt(tk.LogCritical, "%s: %s", e, debug.Stack()) + } + if mh.dp != nil { + mh.dp.DpHooks.DpEbpfUnInit() + } + os.Exit(1) + }() mh.wg.Wait() }