fix: explicit goroutine timeout for registration
This commit is contained in:
parent
842024a6ea
commit
da56eaf164
1 changed files with 20 additions and 7 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package native
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -84,16 +83,30 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
|||
exec.Command("bash", filepath.Join(DeployTo, "pick-module.sh")).Run()
|
||||
|
||||
fmt.Printf("[%s] Registering node...\n", node.Name)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
registerCmd := exec.CommandContext(ctx, "bash", "-c",
|
||||
fmt.Printf("[%s] Registering node...\n", node.Name)
|
||||
registerCmd := exec.Command("bash", "-c",
|
||||
fmt.Sprintf("source %s/env.list 2>/dev/null; %s/register-node job:register -token '%s' -host '%s'",
|
||||
DeployTo, DeployTo, apiToken, apiHost))
|
||||
registerCmd.Dir = DeployTo
|
||||
|
||||
out, regErr := registerCmd.CombinedOutput()
|
||||
if regErr != nil {
|
||||
return fmt.Errorf("register: %w\n%s", regErr, string(out))
|
||||
// Run with explicit timeout
|
||||
type result struct {
|
||||
out []byte
|
||||
err error
|
||||
}
|
||||
ch := make(chan result, 1)
|
||||
go func() {
|
||||
out, err := registerCmd.CombinedOutput()
|
||||
ch <- result{out, err}
|
||||
}()
|
||||
select {
|
||||
case r := <-ch:
|
||||
if r.err != nil {
|
||||
return fmt.Errorf("register: %w\n%s", r.err, string(r.out))
|
||||
}
|
||||
case <-time.After(60 * time.Second):
|
||||
registerCmd.Process.Kill()
|
||||
return fmt.Errorf("registration timed out")
|
||||
}
|
||||
|
||||
// 7. Stop our temporary NGINX, start Wallarm via supervisord
|
||||
|
|
|
|||
Loading…
Reference in a new issue