Skip to content

Commit f1b5950

Browse files
committed
Fix goroutine leak on initialization failures of log input
1 parent 89f93e3 commit f1b5950

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

CHANGELOG.next.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
9292
- Add missing Kubernetes metadata fields to Filebeat CoreDNS module, and fix a documentation error. {pull}11591[11591]
9393
- Reduce memory usage if long lines are truncated to fit `max_bytes` limit. The line buffer is copied into a smaller buffer now. This allows the runtime to release unused memory earlier. {pull}11524[11524]
9494
- Fix memory leak in Filebeat pipeline acker. {pull}12063[12063]
95+
- Fix goroutine leak caused on initialization failures of log input. {pull}12125[12125]
9596

9697
*Heartbeat*
9798

filebeat/input/log/input.go

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func NewInput(
7676
outlet channel.Connector,
7777
context input.Context,
7878
) (input.Input, error) {
79+
cleanupNeeded := true
7980

8081
// Note: underlying output.
8182
// The input and harvester do have different requirements
@@ -87,11 +88,21 @@ func NewInput(
8788
if err != nil {
8889
return nil, err
8990
}
91+
defer func() {
92+
if cleanupNeeded {
93+
out.Close()
94+
}
95+
}()
9096

9197
// stateOut will only be unblocked if the beat is shut down.
9298
// otherwise it can block on a full publisher pipeline, so state updates
9399
// can be forwarded correctly to the registrar.
94100
stateOut := channel.CloseOnSignal(channel.SubOutlet(out), context.BeatDone)
101+
defer func() {
102+
if cleanupNeeded {
103+
stateOut.Close()
104+
}
105+
}()
95106

96107
meta := context.Meta
97108
if len(meta) == 0 {
@@ -137,6 +148,7 @@ func NewInput(
137148

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

151+
cleanupNeeded = false
140152
return p, nil
141153
}
142154

0 commit comments

Comments
 (0)