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

[Agent] Windows spawning process fix #17751

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fixed merge of config {pull}17399[17399]
- Handle abs paths on windows correctly {pull}17461[17461]
- Improved cancellation of agent {pull}17318[17318]
- Fixed process spawning on Windows {pull}17751[17751]

==== New features

Expand Down
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/pkg/core/plugin/process/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package process
import (
"os"
"os/exec"
"path/filepath"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
)
Expand All @@ -18,6 +19,7 @@ func getCmd(logger *logger.Logger, path string, env []string, uid, gid int, arg
cmd := exec.Command(path, arg...)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, env...)
cmd.Dir = filepath.Dir(path)

return cmd
}
7 changes: 5 additions & 2 deletions x-pack/elastic-agent/pkg/core/plugin/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,17 @@ func pushCredentials(w io.Writer, c *Creds) error {

credbytes, err := yaml.Marshal(c)
if err != nil {
return err
return errors.New(err, "decoding credentials")
}

_, err = w.Write(credbytes)
if err != nil {
return errors.New(err, "passing credentials failed")
}

// this gives beat with grpc a bit of time to spin up a goroutine and start a server.
// should be ok until we come up with more clever solution.
// Issue: https://github.com/elastic/beats/v7/issues/15634
<-time.After(1500 * time.Millisecond)
return err
return nil
}