Skip to content

Commit 44077a0

Browse files
authored
Fix goroutine leak on initialization failures of log input (#12125) (#12144)
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 d592918 commit 44077a0

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
@@ -44,6 +44,7 @@ https://github.com/elastic/beats/compare/v6.7.2...6.8[Check the HEAD diff]
4444

4545
- Fix goroutine leak happening when harvesters are dynamically stopped. {pull}11263[11263]
4646
- Fix initialization of the TCP input logger. {pull}11605[11605]
47+
- Fix goroutine leak caused on initialization failures of log input. {pull}12125[12125]
4748
- Fix memory leak in Filebeat pipeline acker. {pull}12063[12063]
4849

4950
*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)