Skip to content

Commit

Permalink
Fix goroutine leak on initialization failures of log input (elastic#1…
Browse files Browse the repository at this point in the history
…2125)

Outlets are created during log input initialization, and if it
fails they were never freed. Handle this case.

(cherry picked from commit f2473d2)
  • Loading branch information
jsoriano committed May 9, 2019
1 parent d4568db commit 3165d11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ https://github.com/elastic/beats/compare/v6.7.2...6.x[Check the HEAD diff]

*Filebeat*

- Fix goroutine leak caused on initialization failures of log input. {pull}12125[12125]

*Heartbeat*

*Journalbeat*
Expand Down
9 changes: 9 additions & 0 deletions filebeat/input/log/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func NewInput(
outlet channel.Connector,
context input.Context,
) (input.Input, error) {
cleanupNeeded := true
cleanupIfNeeded := func(f func() error) {
if cleanupNeeded {
f()
}
}

// Note: underlying output.
// The input and harvester do have different requirements
Expand All @@ -87,11 +93,13 @@ func NewInput(
if err != nil {
return nil, err
}
defer cleanupIfNeeded(out.Close)

// stateOut will only be unblocked if the beat is shut down.
// otherwise it can block on a full publisher pipeline, so state updates
// can be forwarded correctly to the registrar.
stateOut := channel.CloseOnSignal(channel.SubOutlet(out), context.BeatDone)
defer cleanupIfNeeded(stateOut.Close)

meta := context.Meta
if len(meta) == 0 {
Expand Down Expand Up @@ -137,6 +145,7 @@ func NewInput(

logp.Info("Configured paths: %v", p.config.Paths)

cleanupNeeded = false
return p, nil
}

Expand Down

0 comments on commit 3165d11

Please sign in to comment.