From 629fc76976aca4ef26eb083fbf3b7929f6d5aaf0 Mon Sep 17 00:00:00 2001 From: to2false Date: Tue, 2 Jul 2024 09:46:03 +0800 Subject: [PATCH] feat: print the current panic stack --- mapreduce.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mapreduce.go b/mapreduce.go index f6fc04e..c7b07c9 100644 --- a/mapreduce.go +++ b/mapreduce.go @@ -182,7 +182,11 @@ func mapReduceWithPanicChan[T, U, V any](source <-chan T, panicChan *onceChan, m defer func() { drain(collector) if r := recover(); r != nil { - panicChan.write(r) + buf := make([]byte, 64<<10) + n := runtime.Stack(buf, false) + buf = buf[:n] + + panicChan.write(fmt.Sprintf("%v\n%s", r, string(buf))) } finish() }() @@ -269,7 +273,11 @@ func buildSource[T any](generate GenerateFunc[T], panicChan *onceChan) chan T { go func() { defer func() { if r := recover(); r != nil { - panicChan.write(r) + buf := make([]byte, 64<<10) + n := runtime.Stack(buf, false) + buf = buf[:n] + + panicChan.write(fmt.Sprintf("%v\n%s", r, string(buf))) } close(source) }() @@ -316,7 +324,12 @@ func executeMappers[T, U any](mCtx mapperContext[T, U]) { defer func() { if r := recover(); r != nil { atomic.AddInt32(&failed, 1) - mCtx.panicChan.write(r) + + buf := make([]byte, 64<<10) + n := runtime.Stack(buf, false) + buf = buf[:n] + + mCtx.panicChan.write(fmt.Sprintf("%v\n%s", r, string(buf))) } wg.Done() <-pool