Skip to content

Commit d4d2ef3

Browse files
authored
Fix goroutine leak on initialization failures of log input (#12125) (#12143)
Outlets are created during log input initialization, and if it fails they were never freed. Handle this case. (cherry picked from commit f2473d2)
1 parent 4ab7dce commit d4d2ef3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.next.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ https://github.com/elastic/beats/compare/v7.0.0...7.0[Check the HEAD diff]
3636

3737
*Filebeat*
3838

39+
- Fix goroutine leak caused on initialization failures of log input. {pull}12125[12125]
3940
- Fix memory leak in Filebeat pipeline acker. {pull}12063[12063]
4041

4142
*Heartbeat*

filebeat/input/log/input.go

+9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ func NewInput(
7676
outlet channel.Connector,
7777
context input.Context,
7878
) (input.Input, error) {
79+
cleanupNeeded := true
80+
cleanupIfNeeded := func(f func() error) {
81+
if cleanupNeeded {
82+
f()
83+
}
84+
}
7985

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

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

96104
meta := context.Meta
97105
if len(meta) == 0 {
@@ -137,6 +145,7 @@ func NewInput(
137145

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

148+
cleanupNeeded = false
140149
return p, nil
141150
}
142151

0 commit comments

Comments
 (0)