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

[cmd/opampsupervisor] Fix early exits not shutting down client/server in bootstrapping #31944

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
13 changes: 13 additions & 0 deletions .chloggen/fix_opamp-supervisor-bootstrap-error-shutdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: cmd/opampsupervisor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix collector subprocess not being stopped if bootstrapping fails

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31943]
24 changes: 12 additions & 12 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ func (s *Supervisor) getBootstrapInfo() (err error) {
return err
}

defer func() {
if stopErr := srv.Stop(context.Background()); stopErr != nil {
err = errors.Join(err, fmt.Errorf("error when stopping the opamp server: %w", stopErr))
}
}()

cmd, err := commander.NewCommander(
s.logger,
s.config.Agent,
Expand All @@ -300,6 +306,12 @@ func (s *Supervisor) getBootstrapInfo() (err error) {
return err
}

defer func() {
if stopErr := cmd.Stop(context.Background()); stopErr != nil {
err = errors.Join(err, fmt.Errorf("error when stopping the collector: %w", stopErr))
}
}()

select {
// TODO make timeout configurable
case <-time.After(3 * time.Second):
Expand All @@ -309,20 +321,8 @@ func (s *Supervisor) getBootstrapInfo() (err error) {
return errors.New("collector's OpAMP client never connected to the Supervisor")
}
case err = <-done:
if err != nil {
return err
}
}

if err = cmd.Stop(context.Background()); err != nil {
return err
}

if err = srv.Stop(context.Background()); err != nil {
return err
}

return nil
}

func (s *Supervisor) Capabilities() protobufs.AgentCapabilities {
Expand Down
Loading