Skip to content

Commit

Permalink
fix: Race condition on execution when context closes
Browse files Browse the repository at this point in the history
Accessing ProcessState immediately after context
cancels conflict with the Wait() stdlib func:
https://github.com/golang/go/blob/36b81acfa19d9fedf6a0cd60c394fd7a7703834e/src/os/exec/exec.go#L511
  • Loading branch information
kylecarbs committed Feb 2, 2022
1 parent 45fdb69 commit 6994aba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tfexec/cmd_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (tf *Terraform) runTerraformCmd(ctx context.Context, cmd *exec.Cmd) error {
go func() {
<-ctx.Done()
if ctx.Err() == context.DeadlineExceeded || ctx.Err() == context.Canceled {
if cmd != nil && cmd.Process != nil && cmd.ProcessState != nil {
if cmd != nil && cmd.Process != nil {
err := cmd.Process.Kill()
if err != nil {
tf.logger.Printf("error from kill: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion tfexec/cmd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (tf *Terraform) runTerraformCmd(ctx context.Context, cmd *exec.Cmd) error {
go func() {
<-ctx.Done()
if ctx.Err() == context.DeadlineExceeded || ctx.Err() == context.Canceled {
if cmd != nil && cmd.Process != nil && cmd.ProcessState != nil {
if cmd != nil && cmd.Process != nil {
// send SIGINT to process group
err := syscall.Kill(-cmd.Process.Pid, syscall.SIGINT)
if err != nil {
Expand Down

0 comments on commit 6994aba

Please sign in to comment.