diff --git a/.chloggen/fix_opamp-supervisor-bootstrap-error-shutdown.yaml b/.chloggen/fix_opamp-supervisor-bootstrap-error-shutdown.yaml new file mode 100644 index 000000000000..dc6222b5577f --- /dev/null +++ b/.chloggen/fix_opamp-supervisor-bootstrap-error-shutdown.yaml @@ -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] diff --git a/cmd/opampsupervisor/supervisor/supervisor.go b/cmd/opampsupervisor/supervisor/supervisor.go index 87ad84ba543e..ca762660d86e 100644 --- a/cmd/opampsupervisor/supervisor/supervisor.go +++ b/cmd/opampsupervisor/supervisor/supervisor.go @@ -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, @@ -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): @@ -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 {