From a7915db4c396ba80bba819c6e867966f4d36f1c0 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 29 Aug 2020 19:14:21 +0200 Subject: [PATCH] [#347] package trace: printing debugString before instead of at panic (fixup e500d9e) --- daemon/logging/trace/trace.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/daemon/logging/trace/trace.go b/daemon/logging/trace/trace.go index 23a0a14..8421800 100644 --- a/daemon/logging/trace/trace.go +++ b/daemon/logging/trace/trace.go @@ -93,6 +93,7 @@ package trace import ( "context" "fmt" + "os" runtimedebug "runtime/debug" "strings" "time" @@ -241,7 +242,11 @@ func WithTask(ctx context.Context, taskName string) (context.Context, DoneFunc) defer this.mtx.Lock().Unlock() if this.activeChildTasks != 0 { - panic(errors.WithMessagef(ErrTaskStillHasActiveChildTasks, "end task: %v active child tasks\n: %s", this.activeChildTasks, this.debugString())) + if debugEnabled { + // the debugString can be quite long and panic won't print it completely + fmt.Fprintf(os.Stderr, "going to panic due to activeChildTasks:\n%s\n", this.debugString()) + } + panic(errors.WithMessagef(ErrTaskStillHasActiveChildTasks, "end task: %v active child tasks\n", this.activeChildTasks)) } // support idempotent task ends @@ -256,7 +261,11 @@ func WithTask(ctx context.Context, taskName string) (context.Context, DoneFunc) delete(this.parentTask.debugActiveChildTasks, this) } if this.parentTask.activeChildTasks < 0 { - panic(fmt.Sprintf("impl error: parent task with negative activeChildTasks count: %s", this.debugString())) + if debugEnabled { + // the debugString can be quite long and panic won't print it completely + fmt.Fprintf(os.Stderr, "going to panic due to activeChildTasks < 0:\n%s\n", this.parentTask.debugString()) + } + panic(fmt.Sprintf("impl error: parent task with negative activeChildTasks count: %v", this.parentTask.activeChildTasks)) } } return false