Skip to content

Commit b4e272e

Browse files
committed
Remove runTerraformCmd check for cmd.ProcessState
Processes were not being killed because cmd.ProcessState was nil. With this change, processes will be able to make the request to Kill(). Added a temporary log to printout cmd.ProcessState to demonstrate. Will be removed in next commit. Note: this will cause hanging `TestContext_sleepTimeoutExpired` due to a known Golang issue with killing a command when Stdout or Stderr are set to anything besides `nil` or `*os.File`. This is because the Kill does not notify the stdout/stderr subprocesses to stop. `cmd.Wait` (called by `cmd.Run`) waits indefinitely for those subprocesses to stop.
1 parent 400f9d7 commit b4e272e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

tfexec/cmd_default.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ func (tf *Terraform) runTerraformCmd(ctx context.Context, cmd *exec.Cmd) error {
1818
go func() {
1919
<-ctx.Done()
2020
if ctx.Err() == context.DeadlineExceeded || ctx.Err() == context.Canceled {
21-
if cmd != nil && cmd.Process != nil && cmd.ProcessState != nil {
21+
if cmd != nil && cmd.Process != nil {
22+
tf.logger.Printf("killing process. cmd.ProcessState=%v", cmd.ProcessState)
2223
err := cmd.Process.Kill()
2324
if err != nil {
2425
tf.logger.Printf("error from kill: %s", err)

tfexec/cmd_linux.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func (tf *Terraform) runTerraformCmd(ctx context.Context, cmd *exec.Cmd) error {
2323
go func() {
2424
<-ctx.Done()
2525
if ctx.Err() == context.DeadlineExceeded || ctx.Err() == context.Canceled {
26-
if cmd != nil && cmd.Process != nil && cmd.ProcessState != nil {
26+
if cmd != nil && cmd.Process != nil {
27+
tf.logger.Printf("killing process. cmd.ProcessState=%v", cmd.ProcessState)
2728
// send SIGINT to process group
2829
err := syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
2930
if err != nil {

0 commit comments

Comments
 (0)