Skip to content

Commit e2b816b

Browse files
cmacknzblakerouse
andauthored
Wait on the watcher at startup instead of just releasing resources associated with it (#4834)
* Wait on the watcher at startup instead of releasing. * Add changelog. * Update changelog/fragments/1717185708-Stop-creating-a-zombie-process-on-each-restart.yaml Co-authored-by: Blake Rouse <blake.rouse@elastic.co> --------- Co-authored-by: Blake Rouse <blake.rouse@elastic.co>
1 parent 17880c6 commit e2b816b

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Stop creating a zombie process on each restart.
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: "elastic-agent"
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/4834
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

internal/pkg/agent/application/upgrade/rollback.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,24 @@ func InvokeWatcher(log *logger.Logger, agentExecutable string) (*exec.Cmd, error
146146
}
147147

148148
cmd := invokeCmd(agentExecutable)
149-
defer func() {
150-
if cmd.Process != nil {
151-
log.Infof("releasing watcher %v", cmd.Process.Pid)
152-
_ = cmd.Process.Release()
153-
}
154-
}()
155-
156149
log.Infow("Starting upgrade watcher", "path", cmd.Path, "args", cmd.Args, "env", cmd.Env, "dir", cmd.Dir)
157150
if err := cmd.Start(); err != nil {
158151
return nil, fmt.Errorf("failed to start Upgrade Watcher: %w", err)
159152
}
160153

161154
upgradeWatcherPID := cmd.Process.Pid
162155
agentPID := os.Getpid()
156+
157+
go func() {
158+
if err := cmd.Wait(); err != nil {
159+
log.Infow("Upgrade Watcher exited with error", "agent.upgrade.watcher.process.pid", "agent.process.pid", agentPID, upgradeWatcherPID, "error.message", err)
160+
}
161+
}()
162+
163163
log.Infow("Upgrade Watcher invoked", "agent.upgrade.watcher.process.pid", upgradeWatcherPID, "agent.process.pid", agentPID)
164164

165165
return cmd, nil
166+
166167
}
167168

168169
func restartAgent(ctx context.Context, log *logger.Logger, c client.Client) error {

0 commit comments

Comments
 (0)