diff --git a/service/history/ndc/history_replicator.go b/service/history/ndc/history_replicator.go index 9fe37c4e343..66ad3139dd7 100644 --- a/service/history/ndc/history_replicator.go +++ b/service/history/ndc/history_replicator.go @@ -22,6 +22,8 @@ package ndc import ( ctx "context" + "fmt" + "runtime" "time" "github.com/pborman/uuid" @@ -342,7 +344,14 @@ func (r *historyReplicatorImpl) applyEvents( defer func() { if rec := recover(); rec != nil { releaseFn(errPanic) - panic(rec) + stack := make([]byte, 1<<14) // 16kb + n := runtime.Stack(stack, false) + stack = stack[:n] + if retError == nil { + retError = fmt.Errorf("panic: %v, stack: %s", rec, stack) + } else { + retError = fmt.Errorf("panic: %v, stack: %s, previous err: %w", rec, stack, retError) + } } else { releaseFn(retError) }