Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
test: avoid deadlock after failed command execution in pod
Browse files Browse the repository at this point in the history
When executing the command inside the pod failed entirely (for
example, because the pod is not found), "tar cf" got stuck because its
stdout was kept open and "tar.Wait()" blocked forever.
  • Loading branch information
pohly committed Sep 3, 2020
1 parent db11386 commit 389fff8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/e2e/pod/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// RunInPod optionally tars up some files or directories, unpacks them in a container,
// and executes a shell command. Any error is treated as test failure.
func RunInPod(f *framework.Framework, rootdir string, items []string, command string, namespace, pod, container string) (string, string) {
var input io.Reader
var input io.ReadCloser
var cmdPrefix string
if len(items) > 0 {
args := []string{"-cf", "-"}
Expand Down Expand Up @@ -54,6 +54,12 @@ func RunInPod(f *framework.Framework, rootdir string, items []string, command st
CaptureStderr: true,
}
stdout, stderr, err := f.ExecWithOptions(options)
if input != nil {
// Tell tar that it can stop writing. Necessary if ExecWithOptions did not consume
// all output of tar, because otherwise tar is stuck and tar.Wait() above will
// block.
input.Close()
}
framework.ExpectNoError(err, "command failed in namespace %s, pod/container %s/%s:\nstderr:\n%s\nstdout:%s\n",
namespace, pod, container, stderr, stdout)
fmt.Fprintf(GinkgoWriter, "stderr:\n%s\nstdout:\n%s\n",
Expand Down

0 comments on commit 389fff8

Please sign in to comment.