Skip to content

Commit 885a2f1

Browse files
committed
fix close
1 parent fc3e193 commit 885a2f1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cli/exp_rpty.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"context"
66
"encoding/json"
7+
"fmt"
78
"io"
89
"os"
910
"strings"
@@ -191,20 +192,26 @@ func handleRPTY(inv *serpent.Invocation, client *codersdk.Client, args handleRPT
191192
}
192193
}()
193194
go func() {
194-
defer close(stdoutDone)
195+
defer func() {
196+
close(stdoutDone)
197+
}()
195198
_, _ = io.Copy(inv.Stdout, conn)
196199
}()
197200
go func() {
198-
defer close(stderrDone)
201+
defer func() {
202+
close(stderrDone)
203+
}()
199204
_, _ = io.Copy(inv.Stderr, conn)
200205
}()
201206
go func() {
202207
defer close(done)
203-
<-inv.Context().Done()
208+
<-stdoutDone
209+
<-stderrDone
204210
_ = conn.Close()
205211
}()
206212

207213
<-done
214+
_, _ = fmt.Fprintf(inv.Stderr, "Connection closed\n")
208215

209216
return nil
210217
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy