From 9102f53131670ba002b41ab9f2170f4212d2a759 Mon Sep 17 00:00:00 2001 From: Daniel Jiang Date: Mon, 11 Jul 2022 01:41:00 +0800 Subject: [PATCH] Dump stack trace when the plugin server handles panic Mitigate the issue mentioned in #4782 When there's a bug or misconfiguration that causes nil pointer there will be more stack trace information to help us debug. Signed-off-by: Daniel Jiang --- changelogs/unreleased/5110-reasonerjt | 1 + pkg/plugin/framework/handle_panic.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/5110-reasonerjt diff --git a/changelogs/unreleased/5110-reasonerjt b/changelogs/unreleased/5110-reasonerjt new file mode 100644 index 000000000..350f91fa1 --- /dev/null +++ b/changelogs/unreleased/5110-reasonerjt @@ -0,0 +1 @@ +Dump stack trace when the plugin server handles panic \ No newline at end of file diff --git a/pkg/plugin/framework/handle_panic.go b/pkg/plugin/framework/handle_panic.go index 10eb1d2b9..4ea0ec2b5 100644 --- a/pkg/plugin/framework/handle_panic.go +++ b/pkg/plugin/framework/handle_panic.go @@ -17,6 +17,8 @@ limitations under the License. package framework import ( + "runtime/debug" + "github.com/pkg/errors" "google.golang.org/grpc/codes" ) @@ -38,7 +40,8 @@ func handlePanic(p interface{}) error { if _, ok := panicErr.(stackTracer); ok { err = panicErr } else { - err = errors.Wrap(panicErr, "plugin panicked") + errWithStacktrace := errors.Errorf("%v, stack trace: %s", panicErr, debug.Stack()) + err = errors.Wrap(errWithStacktrace, "plugin panicked") } }