mirror of https://github.com/coder/coder.git
fix(codersdk): abort in-progress writes/reads when closing websocket (#12650)
Fixes #9203 Related #12065 Also, adds some basic tracing infrastructure that we can build upon for more improvements.
This commit is contained in:
parent
92aa1eba97
commit
0d86dca852
17
cli/root.go
17
cli/root.go
|
@ -18,6 +18,7 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/trace"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
@ -139,6 +140,22 @@ func (r *RootCmd) AGPL() []*serpent.Command {
|
||||||
|
|
||||||
// Main is the entrypoint for the Coder CLI.
|
// Main is the entrypoint for the Coder CLI.
|
||||||
func (r *RootCmd) RunMain(subcommands []*serpent.Command) {
|
func (r *RootCmd) RunMain(subcommands []*serpent.Command) {
|
||||||
|
// This configuration is not available as a standard option because we
|
||||||
|
// want to trace the entire program, including Options parsing.
|
||||||
|
goTraceFilePath, ok := os.LookupEnv("CODER_GO_TRACE")
|
||||||
|
if ok {
|
||||||
|
traceFile, err := os.OpenFile(goTraceFilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to open trace file: %v", err))
|
||||||
|
}
|
||||||
|
defer traceFile.Close()
|
||||||
|
|
||||||
|
if err := trace.Start(traceFile); err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to start trace: %v", err))
|
||||||
|
}
|
||||||
|
defer trace.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixMicro())
|
rand.Seed(time.Now().UnixMicro())
|
||||||
|
|
||||||
cmd, err := r.Command(subcommands)
|
cmd, err := r.Command(subcommands)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (c *wsNetConn) Write(b []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *wsNetConn) Close() error {
|
func (c *wsNetConn) Close() error {
|
||||||
defer c.cancel()
|
c.cancel()
|
||||||
return c.Conn.Close()
|
return c.Conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue