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
|
package native
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"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()
|
exec.Command("bash", filepath.Join(DeployTo, "pick-module.sh")).Run()
|
||||||
|
|
||||||
fmt.Printf("[%s] Registering node...\n", node.Name)
|
fmt.Printf("[%s] Registering node...\n", node.Name)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
fmt.Printf("[%s] Registering node...\n", node.Name)
|
||||||
defer cancel()
|
registerCmd := exec.Command("bash", "-c",
|
||||||
registerCmd := exec.CommandContext(ctx, "bash", "-c",
|
|
||||||
fmt.Sprintf("source %s/env.list 2>/dev/null; %s/register-node job:register -token '%s' -host '%s'",
|
fmt.Sprintf("source %s/env.list 2>/dev/null; %s/register-node job:register -token '%s' -host '%s'",
|
||||||
DeployTo, DeployTo, apiToken, apiHost))
|
DeployTo, DeployTo, apiToken, apiHost))
|
||||||
registerCmd.Dir = DeployTo
|
registerCmd.Dir = DeployTo
|
||||||
|
|
||||||
out, regErr := registerCmd.CombinedOutput()
|
// Run with explicit timeout
|
||||||
if regErr != nil {
|
type result struct {
|
||||||
return fmt.Errorf("register: %w\n%s", regErr, string(out))
|
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
|
// 7. Stop our temporary NGINX, start Wallarm via supervisord
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue