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

Skip to content

Commit 4ce1448

Browse files
authored
fix(cli): generate correctly named file in DumpHandler (#12409)
1 parent afcea74 commit 4ce1448

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

cli/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
149149

150150
// DumpHandler does signal handling, so we call it after the
151151
// reaper.
152-
go DumpHandler(ctx)
152+
go DumpHandler(ctx, "agent")
153153

154154
logWriter := &lumberjackWriteCloseFixer{w: &lumberjack.Logger{
155155
Filename: filepath.Join(logDir, "coder-agent.log"),

cli/root.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ func (r *RootCmd) Verbosef(inv *clibase.Invocation, fmtStr string, args ...inter
937937
// A SIGQUIT handler will not be registered if GOTRACEBACK=crash.
938938
//
939939
// On Windows this immediately returns.
940-
func DumpHandler(ctx context.Context) {
940+
func DumpHandler(ctx context.Context, name string) {
941941
if runtime.GOOS == "windows" {
942942
// free up the goroutine since it'll be permanently blocked anyways
943943
return
@@ -992,7 +992,11 @@ func DumpHandler(ctx context.Context) {
992992
if err != nil {
993993
dir = os.TempDir()
994994
}
995-
fpath := filepath.Join(dir, fmt.Sprintf("coder-agent-%s.dump", time.Now().Format("2006-01-02T15:04:05.000Z")))
995+
// Make the time filesystem-safe, for example ":" is not
996+
// permitted on many filesystems. Note that Z here only appends
997+
// Z to the string, it does not actually change the time zone.
998+
filesystemSafeTime := time.Now().UTC().Format("2006-01-02T15-04-05.000Z")
999+
fpath := filepath.Join(dir, fmt.Sprintf("coder-%s-%s.dump", name, filesystemSafeTime))
9961000
_, _ = fmt.Fprintf(os.Stderr, "writing dump to %q\n", fpath)
9971001

9981002
f, err := os.Create(fpath)

cli/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
289289
cliui.Warnf(inv.Stderr, "YAML support is experimental and offers no compatibility guarantees.")
290290
}
291291

292-
go DumpHandler(ctx)
292+
go DumpHandler(ctx, "coderd")
293293

294294
// Validate bind addresses.
295295
if vals.Address.String() != "" {

enterprise/cli/proxyserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
119119
defer topCancel()
120120
closers.Add(topCancel)
121121

122-
go cli.DumpHandler(ctx)
122+
go cli.DumpHandler(ctx, "workspace-proxy")
123123

124124
cli.PrintLogo(inv, "Coder Workspace Proxy")
125125
logger, logCloser, err := clilog.New(clilog.FromDeploymentValues(cfg)).Build(inv)

0 commit comments

Comments
 (0)