Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace timer with context.Done #2471

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"time"

"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/log"
)

const (
Expand Down Expand Up @@ -49,13 +48,15 @@
return fmt.Errorf("start command: %w", err)
}

timer := time.AfterFunc(timeout, func() {
log.Println("hook timed out: killing command")
_ = cmd.Process.Kill()
_ = stdout.Close()
})

defer timer.Stop()
go func() {
select {

Check failure on line 52 in cmd/hook.go

View workflow job for this annotation

GitHub Actions / Main Process

S1000: should use a simple channel send/receive instead of `select` with a single case (gosimple)
case <-ctxCmd.Done():
if ctxCmd.Err() != nil {
_ = cmd.Process.Kill()
_ = stdout.Close()
}
}
}()

scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
Expand Down
5 changes: 5 additions & 0 deletions cmd/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/stretchr/testify/require"
)

func Test_launchHook(t *testing.T) {
err := launchHook("echo foo", 1*time.Second, map[string]string{})
require.NoError(t, err)
}

func Test_launchHook_errors(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
Expand Down
Loading