fix race condition for exec

This commit is contained in:
criyle 2019-09-14 22:44:14 -07:00
parent 998ffb02c0
commit 38ef6b572a
3 changed files with 6 additions and 3 deletions

View File

@ -62,11 +62,13 @@ func (m *Master) Execve(done <-chan struct{}, param *ExecveParam) (<-chan types.
// make sure goroutine not leaked (blocked) even if result is not consumed
wait := make(chan types.Result, 1)
waitDone := make(chan struct{})
killDone := make(chan struct{})
// Wait
go func() {
defer close(wait)
reply2, _, _ := m.recvReply()
close(waitDone)
<-killDone
wait <- types.Result{
ExitStatus: reply2.ExitStatus,
Status: reply2.Status,
@ -81,6 +83,7 @@ func (m *Master) Execve(done <-chan struct{}, param *ExecveParam) (<-chan types.
case <-waitDone:
}
m.sendCmd(&Cmd{Cmd: cmdKill}, nil)
close(killDone)
}()
return wait, nil
}

2
go.mod
View File

@ -4,5 +4,5 @@ go 1.12
require (
github.com/seccomp/libseccomp-golang v0.9.1
golang.org/x/sys v0.0.0-20190907184412-d223b2b6db03
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7
)

4
go.sum
View File

@ -1,4 +1,4 @@
github.com/seccomp/libseccomp-golang v0.9.1 h1:NJjM5DNFOs0s3kYE1WUOr6G8V97sdt46rlXTMfXGWBo=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
golang.org/x/sys v0.0.0-20190907184412-d223b2b6db03 h1:b3JiLYVaG9kHjTcOQIoUh978YMCO7oVTQQBLudU47zY=
golang.org/x/sys v0.0.0-20190907184412-d223b2b6db03/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7 h1:wYqz/tQaWUgGKyx+B/rssSE6wkIKdY5Ee6ryOmzarIg=
golang.org/x/sys v0.0.0-20190913121621-c3b328c6e5a7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=