You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
go run main.go will create a bash process and a sleep process, and when timeout, the bash process will be killed, and sleep process will hosting by process which pid=1.
but cmd.CombinedOutput() not exit.
will block at err := <-c.errch,because in start method,we blocked in fn,and don't send error to c.errch.so the program don't exit after timeout.
// os/exec/exec.go
func (c *Cmd) Start() error {
// ...
if c.ctx != nil {
c.waitDone = make(chan struct{})
go func() {
select {
case <-c.ctx.Done():
c.Process.Kill()
c.closeDescriptors(c.closeAfterWait)
case <-c.waitDone:
}
}()
}
//...
maybe we can close read pipe c.closeDescriptors(c.closeAfterWait) in case <-c.ctx.Done() .
I tried this, the bash process will be killed after timeout, and the program will exit, the sleep process hosting by the process which pid=1.
The text was updated successfully, but these errors were encountered:
lixd
changed the title
affected/package: os/exec, timeout notwork.
affected/package: os/exec, context not work.
Jul 6, 2022
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
reproduce in go1.18.3
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
and /root/sleep.sh:
#!/bin/bash sleep 1200
run this
What did you expect to see?
when timeout, the program exits.
What did you see instead?
go run main.go
will create a bash process and a sleep process, and when timeout, the bash process will be killed, and sleep process will hosting by process which pid=1.but
cmd.CombinedOutput()
not exit.Others
![image](https://user-images.githubusercontent.com/31980412/177514522-a0c6f741-8389-4b5e-9db3-30553ee3241c.png)
after timeoutwill block at fn(),so there is no error send to c.errch
and the fn is thie:
block at
io.Copy(w, pr)
,because the read pipe pr never close。will block at
err := <-c.errch
,because in start method,we blocked in fn,and don't send error to c.errch.so the program don't exit after timeout.maybe we can close read pipe
c.closeDescriptors(c.closeAfterWait)
incase <-c.ctx.Done()
.I tried this, the bash process will be killed after timeout, and the program will exit, the sleep process hosting by the process which pid=1.
The text was updated successfully, but these errors were encountered: