mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: lock log sink against concurrent write and close (#10668)
fixes #10663
This commit is contained in:
+4
-2
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"github.com/coder/coder/v2/cli/clibase"
|
||||
"github.com/coder/coder/v2/cli/cliui"
|
||||
"github.com/coder/coder/v2/cli/cliutil"
|
||||
"github.com/coder/coder/v2/coderd/autobuild/notify"
|
||||
"github.com/coder/coder/v2/coderd/util/ptr"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
@@ -114,12 +115,13 @@ func (r *RootCmd) ssh() *clibase.Cmd {
|
||||
if err != nil {
|
||||
return xerrors.Errorf("error opening %s for logging: %w", logDirPath, err)
|
||||
}
|
||||
dc := cliutil.DiscardAfterClose(logFile)
|
||||
go func() {
|
||||
wg.Wait()
|
||||
_ = logFile.Close()
|
||||
_ = dc.Close()
|
||||
}()
|
||||
|
||||
logger = slog.Make(sloghuman.Sink(logFile))
|
||||
logger = logger.AppendSinks(sloghuman.Sink(dc))
|
||||
if r.verbose {
|
||||
logger = logger.Leveled(slog.LevelDebug)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user