From d574b59fc71e52ac7feead94348ee61ef8d16a1c Mon Sep 17 00:00:00 2001 From: Patrick Mezard Date: Sun, 10 May 2015 15:35:52 +0200 Subject: os: fix a race between Process.signal() and wait() on Windows 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. Fixes #9382 Change-Id: Iefcc687a1166d5961c8f27154647b9b15a0f748a Reviewed-on: https://go-review.googlesource.com/9904 Reviewed-by: Alex Brainman Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- src/os/exec.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/os/exec.go') diff --git a/src/os/exec.go b/src/os/exec.go index 5aea3098b5..15e95b9172 100644 --- a/src/os/exec.go +++ b/src/os/exec.go @@ -13,8 +13,8 @@ import ( // Process stores the information about a process created by StartProcess. type Process struct { Pid int - handle uintptr - isdone uint32 // process has been successfully waited on, non zero if true + handle uintptr // handle is accessed atomically on Windows + isdone uint32 // process has been successfully waited on, non zero if true } func newProcess(pid int, handle uintptr) *Process { -- cgit v1.3