mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 11:05:45 +00:00
wgengine/magicsock: fix latent data race in test
logBufWriter had no serialization. It just so happens that none of its users currently ever log concurrently. Make it safe for concurrent use. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
parent
01e159b610
commit
4f4dae32dd
@ -1431,8 +1431,13 @@ func BenchmarkReceiveFrom_Native(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
// logBufWriterMu serializes writes made by logBufWriter.
|
||||
var logBufWriterMu sync.Mutex
|
||||
|
||||
func logBufWriter(buf *bytes.Buffer) logger.Logf {
|
||||
return func(format string, a ...interface{}) {
|
||||
logBufWriterMu.Lock()
|
||||
defer logBufWriterMu.Unlock()
|
||||
fmt.Fprintf(buf, format, a...)
|
||||
if !bytes.HasSuffix(buf.Bytes(), []byte("\n")) {
|
||||
buf.WriteByte('\n')
|
||||
|
Loading…
Reference in New Issue
Block a user