From: Dmitriy Vyukov Date: Fri, 21 Sep 2012 19:54:15 +0000 (+1000) Subject: [release-branch.go1] os: fix data race in epipecheck() X-Git-Tag: go1.0.3~136 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=53299c4326db169936f831b282f4f5202b04ddbf;p=gostls13.git [release-branch.go1] os: fix data race in epipecheck() ««« backport 8b3bf65c620c os: fix data race in epipecheck() Fixes #3860. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6443051 »»» --- diff --git a/src/pkg/os/file_posix.go b/src/pkg/os/file_posix.go index 073bd56a47..ea42cc67b5 100644 --- a/src/pkg/os/file_posix.go +++ b/src/pkg/os/file_posix.go @@ -7,6 +7,7 @@ package os import ( + "sync/atomic" "syscall" "time" ) @@ -15,12 +16,11 @@ func sigpipe() // implemented in package runtime func epipecheck(file *File, e error) { if e == syscall.EPIPE { - file.nepipe++ - if file.nepipe >= 10 { + if atomic.AddInt32(&file.nepipe, 1) >= 10 { sigpipe() } } else { - file.nepipe = 0 + atomic.StoreInt32(&file.nepipe, 0) } } diff --git a/src/pkg/os/file_unix.go b/src/pkg/os/file_unix.go index 6271c3189e..12daa70a76 100644 --- a/src/pkg/os/file_unix.go +++ b/src/pkg/os/file_unix.go @@ -24,7 +24,7 @@ type file struct { fd int name string dirinfo *dirInfo // nil unless directory being read - nepipe int // number of consecutive EPIPE in Write + nepipe int32 // number of consecutive EPIPE in Write } // Fd returns the integer Unix file descriptor referencing the open file. diff --git a/src/pkg/os/file_windows.go b/src/pkg/os/file_windows.go index 88fa77bb84..320ee22518 100644 --- a/src/pkg/os/file_windows.go +++ b/src/pkg/os/file_windows.go @@ -25,7 +25,6 @@ type file struct { fd syscall.Handle name string dirinfo *dirInfo // nil unless directory being read - nepipe int // number of consecutive EPIPE in Write l sync.Mutex // used to implement windows pread/pwrite }