From 0563decd0ab8f2ce99b7eadef2e4b81557784cfb Mon Sep 17 00:00:00 2001 From: arkbriar Date: Wed, 2 Nov 2022 11:36:22 +0800 Subject: [PATCH] Propagate the panic with a channel Signed-off-by: arkbriar Kubernetes-commit: b7e6c23e9f73e4cc0209e94fe95c5e2809998bf6 --- tools/remotecommand/remotecommand.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/remotecommand/remotecommand.go b/tools/remotecommand/remotecommand.go index 4e22a970c3..662a3cb4ac 100644 --- a/tools/remotecommand/remotecommand.go +++ b/tools/remotecommand/remotecommand.go @@ -27,9 +27,8 @@ import ( "k8s.io/apimachinery/pkg/util/httpstream" "k8s.io/apimachinery/pkg/util/remotecommand" - "k8s.io/apimachinery/pkg/util/runtime" restclient "k8s.io/client-go/rest" - spdy "k8s.io/client-go/transport/spdy" + "k8s.io/client-go/transport/spdy" ) // StreamOptions holds information pertaining to the current streaming session: @@ -161,14 +160,20 @@ func (e *streamExecutor) StreamWithContext(ctx context.Context, options StreamOp } defer conn.Close() + panicChan := make(chan any, 1) errorChan := make(chan error, 1) go func() { - defer runtime.HandleCrash() - defer close(errorChan) + defer func() { + if p := recover(); p != nil { + panicChan <- p + } + }() errorChan <- streamer.stream(conn) }() select { + case p := <-panicChan: + panic(p) case err := <-errorChan: return err case <-ctx.Done():