Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 765edb8

Browse files
committed
fix(codersdk): abort in-progress writes/reads when closing websocket
Fixes #9203 Also, adds some basic tracing infrastructure that we can build upon for more improvements.
1 parent 0e8ebb9 commit 765edb8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cli/root.go

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"os/signal"
1919
"path/filepath"
2020
"runtime"
21+
"runtime/trace"
2122
"strings"
2223
"syscall"
2324
"text/tabwriter"
@@ -139,6 +140,22 @@ func (r *RootCmd) AGPL() []*serpent.Command {
139140

140141
// Main is the entrypoint for the Coder CLI.
141142
func (r *RootCmd) RunMain(subcommands []*serpent.Command) {
143+
// This configuration is not available as a standard option because we
144+
// want to trace the entire program, including Options parsing.
145+
goTraceFilePath, ok := os.LookupEnv("CODER_GO_TRACE")
146+
if ok {
147+
traceFile, err := os.OpenFile(goTraceFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o644)
148+
if err != nil {
149+
panic(fmt.Sprintf("failed to open trace file: %v", err))
150+
}
151+
defer traceFile.Close()
152+
153+
if err := trace.Start(traceFile); err != nil {
154+
panic(fmt.Sprintf("failed to start trace: %v", err))
155+
}
156+
defer trace.Stop()
157+
}
158+
142159
rand.Seed(time.Now().UnixMicro())
143160

144161
cmd, err := r.Command(subcommands)

codersdk/websocket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (c *wsNetConn) Write(b []byte) (n int, err error) {
3232
}
3333

3434
func (c *wsNetConn) Close() error {
35-
defer c.cancel()
35+
c.cancel()
3636
return c.Conn.Close()
3737
}
3838

0 commit comments

Comments
 (0)