Skip to content

Commit 52a362a

Browse files
committed
fix: proper context cancel detection
1 parent 23f4366 commit 52a362a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/cmd/compute/exec-pipe.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package compute
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"io"
@@ -53,6 +54,9 @@ func newComputeExecPipe() *cobra.Command {
5354
timeout, err := cmd.Flags().GetInt("timeout")
5455
cobra.CheckErr(err)
5556

57+
ctx, cancel := context.WithCancel(ctx)
58+
defer cancel()
59+
5660
client := api.NewComputeClient()
5761
stream := client.ExecPipe(ctx)
5862
stream.RequestHeader().Set("Authorization", "Bearer "+token)
@@ -77,6 +81,11 @@ func newComputeExecPipe() *cobra.Command {
7781
go func() {
7882
buf := make([]byte, 4096) //nolint:mnd
7983
for {
84+
select {
85+
case <-ctx.Done():
86+
return
87+
default:
88+
}
8089
n, err := os.Stdin.Read(buf)
8190
if n > 0 {
8291
data := make([]byte, n)

0 commit comments

Comments
 (0)