mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-02 00:02:01 +00:00
virtcontainers: Properly end up go routines using channels
Those different files were all calling into a go routine that was eventually reporting some result through a go channel. The problem was the way those routine were implemented, as they were hanging around forever. Indeed, nothing was actually listening to the channel in some cases, and those routines never ended. This was one of the problem detected by the fact that our unit tests needed more time to pass because when they were all run in parallel, the resources consumed by those routines were increasing the time for other tests to complete. Fixes #208 Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
2c3cfed608
commit
92577c635f
@ -242,8 +242,9 @@ func TestCCShimStartDetachSuccessful(t *testing.T) {
|
||||
|
||||
testCCShimStart(t, sandbox, params, false)
|
||||
|
||||
readCh := make(chan error)
|
||||
readCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(readCh)
|
||||
bufStdout := make([]byte, 1024)
|
||||
n, err := rStdout.Read(bufStdout)
|
||||
if err != nil && err != io.EOF {
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -82,9 +83,11 @@ func (h *Hook) runHook() error {
|
||||
return fmt.Errorf("%s: stdout: %s, stderr: %s", err, stdout.String(), stderr.String())
|
||||
}
|
||||
} else {
|
||||
done := make(chan error)
|
||||
|
||||
go func() { done <- cmd.Wait() }()
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- cmd.Wait()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-done:
|
||||
@ -92,6 +95,10 @@ func (h *Hook) runHook() error {
|
||||
return fmt.Errorf("%s: stdout: %s, stderr: %s", err, stdout.String(), stderr.String())
|
||||
}
|
||||
case <-time.After(time.Duration(h.Timeout) * time.Second):
|
||||
if err := syscall.Kill(cmd.Process.Pid, syscall.SIGKILL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return fmt.Errorf("Hook timeout")
|
||||
}
|
||||
}
|
||||
|
@ -236,8 +236,9 @@ func TestKataShimStartDetachSuccessful(t *testing.T) {
|
||||
|
||||
testKataShimStart(t, sandbox, params, false)
|
||||
|
||||
readCh := make(chan error)
|
||||
readCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(readCh)
|
||||
bufStdout := make([]byte, 1024)
|
||||
n, err := rStdout.Read(bufStdout)
|
||||
if err != nil && err != io.EOF {
|
||||
|
Loading…
Reference in New Issue
Block a user