Skip to content

Commit 92776a7

Browse files
authored
remove process cancelling goroutine (#190)
the goroutine is redundant, and blocks the actual return of the function when the ctx is done. ``` Error: -19T14:46:26.742Z [ERROR] provider.terraform-provider-oci_v0.0.17: failed to kill process: @caller=github.com/chainguard-dev/terraform-provider-oci/internal/provider/exec_test_data_source.go:194 error="os: process already finished" tf_data_source_type=oci_exec_test tf_provider_addr=registry.terraform.io/chainguard-dev/oci tf_req_id=c0da7202-2dff-f56f-aebc-de6d70d42686 @module=oci tf_rpc=ReadDataSource timestamp=2024-12-19T14:46:26.741Z ``` by removing it, we remove the duplicate cancellation handling (the timeout is already plumbed through the context), and the done signal is already handled by `exec.CommandContext`. additionally, the process.Kill() is already handled by `exec.CommandContext`: https://cs.opensource.google/go/go/+/master:src/os/exec/exec.go;l=485
1 parent 0fae112 commit 92776a7

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

internal/provider/exec_test_data_source.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,9 @@ func (d *ExecTestDataSource) Read(ctx context.Context, req datasource.ReadReques
187187
}
188188

189189
cmd := exec.CommandContext(ctx, "sh", "-c", data.Script.ValueString())
190-
go func() {
191-
select {
192-
case <-ctx.Done():
193-
if err := cmd.Process.Kill(); err != nil {
194-
tflog.Error(ctx, "failed to kill process", map[string]interface{}{"error": err})
195-
}
196-
case <-time.After(time.Duration(timeout) * time.Second):
197-
if err := cmd.Process.Kill(); err != nil {
198-
tflog.Error(ctx, "failed to kill process", map[string]interface{}{"error": err})
199-
}
200-
}
201-
}()
202190
cmd.Env = env
203191
cmd.Dir = data.WorkingDir.ValueString()
192+
204193
fullout, err := cmd.CombinedOutput()
205194
data.Output = types.StringValue("") // always empty.
206195

0 commit comments

Comments
 (0)