Commit ab9ccede authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

os: fix data race in epipecheck()

Fixes #3860.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/6443051
parent c49af2cc
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package os package os
import ( import (
"sync/atomic"
"syscall" "syscall"
"time" "time"
) )
...@@ -15,12 +16,11 @@ func sigpipe() // implemented in package runtime ...@@ -15,12 +16,11 @@ func sigpipe() // implemented in package runtime
func epipecheck(file *File, e error) { func epipecheck(file *File, e error) {
if e == syscall.EPIPE { if e == syscall.EPIPE {
file.nepipe++ if atomic.AddInt32(&file.nepipe, 1) >= 10 {
if file.nepipe >= 10 {
sigpipe() sigpipe()
} }
} else { } else {
file.nepipe = 0 atomic.StoreInt32(&file.nepipe, 0)
} }
} }
......
...@@ -24,7 +24,7 @@ type file struct { ...@@ -24,7 +24,7 @@ type file struct {
fd int fd int
name string name string
dirinfo *dirInfo // nil unless directory being read 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. // Fd returns the integer Unix file descriptor referencing the open file.
......
...@@ -25,7 +25,6 @@ type file struct { ...@@ -25,7 +25,6 @@ type file struct {
fd syscall.Handle fd syscall.Handle
name string name string
dirinfo *dirInfo // nil unless directory being read dirinfo *dirInfo // nil unless directory being read
nepipe int // number of consecutive EPIPE in Write
l sync.Mutex // used to implement windows pread/pwrite l sync.Mutex // used to implement windows pread/pwrite
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment