From 2b416c3c961a9829f7ca97dd44690e71719f68f2 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 28 Nov 2023 09:20:32 -0800 Subject: [PATCH] quic/qlog: create log files with O_EXCL Avoid confusing log corruption if two loggers try to write to the same file simultaneously. Change-Id: I3bfbcf56aa55c778ada0178d7c662c414878c9d1 Reviewed-on: https://go-review.googlesource.com/c/net/+/545577 Reviewed-by: Jonathan Amsterdam LUCI-TryBot-Result: Go LUCI --- internal/quic/qlog/qlog.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/quic/qlog/qlog.go b/internal/quic/qlog/qlog.go index 0e71d71aae..e54c839f0a 100644 --- a/internal/quic/qlog/qlog.go +++ b/internal/quic/qlog/qlog.go @@ -180,7 +180,7 @@ func newTraceWriter(opts HandlerOptions, info TraceInfo) (io.WriteCloser, error) if !filepath.IsLocal(filename) { return nil, errors.New("invalid trace filename") } - w, err = os.Create(filepath.Join(opts.Dir, filename)) + w, err = os.OpenFile(filepath.Join(opts.Dir, filename), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0666) } else { err = errors.New("no log destination") }