Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
os: data race between Process.Wait and Kill #9382
go version go1.4 windows/amd64
Looks like there is a data race between os.Process.Wait() and os.Process.Kill(). The documentation does not state these operations can be run concurrently, but if they cannot, can you suggest a way to implement some kind of timeout on started process? Like "kill it if it runs more than N seconds".
The following code triggers the issue:
when run with:
Process.handle was accessed without synchronization while wait() and signal() could be called concurrently. A first solution was to add a Mutex in Process but it was probably too invasive given Process.handle is only used on Windows. This version uses atomic operations to read the handle value. There is still a race between isDone() and the value of the handle, but it only leads to slightly incorrect error codes. The caller may get a: errors.New("os: process already finished") instead of: syscall.EINVAL which sounds harmless. I did add accessors for the atomic operations since they only exist in the Windows version. Fixes golang#9382