Skip to content

Commit

Permalink
Fix goroutine leak in local.file
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum committed Feb 9, 2024
1 parent 1a035ee commit f4de1bb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions component/local/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func New(o component.Options, args Arguments) (*Component, error) {
}
// Perform an update which will immediately set our exports to the initial
// contents of the file.
if err = c.Update(args); err != nil {
// UpdateArgs instead of Update to prevent starting goroutines if Run() is not called.
if err = c.UpdateArgs(args); err != nil {
return nil, err
}
return c, nil
Expand Down Expand Up @@ -184,8 +185,7 @@ func (c *Component) readFile() error {
return nil
}

// Update implements component.Component.
func (c *Component) Update(args component.Arguments) error {
func (c *Component) UpdateArgs(args component.Arguments) error {
newArgs := args.(Arguments)

if newArgs.PollFrequency <= 0 {
Expand All @@ -200,6 +200,16 @@ func (c *Component) Update(args component.Arguments) error {
if err := c.readFile(); err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
return nil
}

// Update implements component.Component.
func (c *Component) Update(args component.Arguments) error {

err := c.UpdateArgs(args)
if err != nil {
return err
}

// Each detector is dedicated to a single file path. We'll naively shut down
// the existing detector (if any) before setting up a new one to make sure
Expand Down

0 comments on commit f4de1bb

Please sign in to comment.