You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 0s : start the child process// 2s : stop the child process// 7s : the library attempts to kill the child processfuncrun() (int, error) {
process, err:=child.New(&child.NewInput{
Command: "./my-script.sh", // a script that disregards SIGTERMStdout: os.Stdout,
KillSignal: syscall.SIGTERM,
KillTimeout: 5*time.Second,
})
iferr!=nil {
return-2, err
}
iferr:=process.Start(); err!=nil {
return-3, fmt.Errorf("could not start the process: %s", err)
}
select {
case<-time.After(2*time.Second):
process.Stop()
returnSuccessfullyStoppedTheProcess, nilcaseexitCode:=<-process.ExitCh():
returnexitCode, nil
}
}
funcTestRunOnce(t*testing.T) {
c, err:=run()
iferr!=nil {
t.Fatal(err)
}
ifc!=SuccessfullyStoppedTheProcess {
t.Fatalf("unexpected return code: %d", c)
}
}
Debug output
$ go test -run TestRunOnce --race
2023/05/25 13:55:39 [INFO] (child) spawning: ./my-script.sh
sleeping for 20s
sleeping for 19s
2023/05/25 13:55:41 [INFO] (child) stopping process
received SIGTERM; ignoring it
sleeping for 18s
sleeping for 17s
sleeping for 16s
sleeping for 15s
sleeping for 14s
==================
WARNING: DATA RACE
Write at 0x00c0000f20c0 by goroutine 6:
github.com/hashicorp/consul-template/child.(*Child).kill.func1()
/Users/avean/go/pkg/mod/github.com/hashicorp/consul-template@v0.32.0/child/child.go:439 +0x84
runtime.deferreturn()
...
Previous read at 0x00c0000f20c0 by goroutine 9:
github.com/hashicorp/consul-template/child.(*Child).kill.func2()
/Users/avean/go/pkg/mod/github.com/hashicorp/consul-template@v0.32.0/child/child.go:457 +0x70
...
Consul Template version
v0.32.0
Configuration
The following minimal example to demonstrates the race. The full code can be found at averche/test-go/consul-template-child-gorace:
Debug output
The full output can be found @ averche/test-go/consul-template-child-gorace.
Expected behavior
We attempt to stop the script, after 5 seconds, the script is killed immediately.
Actual behavior
The script is killed correctly but a go race is detected in tests.
Steps to reproduce
git clone /~https://github.com/averche/test-go && cd test-go/consul-template-child-gorace/
go test -run TestRunOnce --race
The text was updated successfully, but these errors were encountered: