Skip to content

Commit

Permalink
Propagate the panic with a channel
Browse files Browse the repository at this point in the history
Signed-off-by: arkbriar <[email protected]>

Kubernetes-commit: b7e6c23e9f73e4cc0209e94fe95c5e2809998bf6
  • Loading branch information
arkbriar authored and k8s-publishing-bot committed Nov 2, 2022
1 parent 2362c7b commit 0563dec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/remotecommand/remotecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 0563dec

Please sign in to comment.