Hi, community!

The problem is happening in a more complex program but I’ve written a 
simple program to reproduce it.

package main import ( "context" "fmt" "os/exec" "time" ) func main() { ctx, 
cancel := context.WithTimeout(context.Background(), 
time.Duration(30000)*time.Millisecond) 
defer cancel() c := exec.CommandContext(ctx, "cmd.exe", "/c", "start", 
"/wait", "notepad.exe") _, err := c.Output() fmt.Println("end", "err", err) 
}

Steps to reproduce:

   - Just run the program and observe the process tree (using Process 
   Explorer or similar)

Expected behavior: c.Output() call returns as soon as cmd.exe process is 
killed on context timeout.

Observed behavior: the program blocks “forever” on c.Output() call until I 
kill the notepad.exe process manually.

Debugging shows that Go is blocked on (os/exec_windows.go):

s, e := syscall.WaitForSingleObject(syscall.Handle(handle), 
syscall.INFINITE)

waiting on the cmd.exe process handle (even after it was killed).

I also tested on Mac (was curious about the behavior on non-windows OSes) 
and on Mac c.Output() returns as soon as the parent process is killed 
(children process keeps running but it doesn’t cause c.Output() call to 
block)

Thank you in advance!

Best regards!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9c4f3404-06f2-4175-8859-16021150050an%40googlegroups.com.

Reply via email to