Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filebeat: Fix leak in log harvester (#6797) #6829

Merged
merged 1 commit into from
Apr 13, 2018
Merged

Conversation

adriansr
Copy link
Contributor

This patch reorganizes a little bit how the log harvester works, so that suboutlets are only created when the harvester is ready to use them (inside Run()), instead of being passed during constructor.

This prevents a goroutine leak when the harvester's Setup() call fails and Run() is never invoked.

Fixes #6797

@@ -52,6 +52,10 @@ var (
ErrClosed = errors.New("reader closed")
)

type OutletFactory interface {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type OutletFactory should have comment or be unexported

// OutletFactory provides an outlet for the harvester
type OutletFactory interface {
GetOutlet() channel.Outleter
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type can be changed to type OutletFactory func() channel.Outleter.

By just passing a function/closure, we don't need to add another public method to each Input type, but still get the lazy initialization we want.

@urso
Copy link

urso commented Apr 11, 2018

The lazy init approach looks safe. All filebeat tests have been green as well. We only must be sure the factory is called only once.

The SubOutlet created by the log file prospector must not be created multiple times from within the same harvester. I don't think that's the case. Buhaving a local function/closure, we can add a counter/check, checking the factory is indeed not being called twice. Alternatively remember the current SubOutlet.

@ruflin
Copy link
Member

ruflin commented Apr 11, 2018

Could you add a Changelog?

@adriansr
Copy link
Contributor Author

adriansr commented Apr 11, 2018

Thanks @urso and @ruflin, both comments addressed.

This patch reorganizes a little bit how the log harvester works, so that
suboutlets are only created when the harvester is ready to use them
(inside Run()), instead of being passed during constructor.

This prevents a memory leak caused by some internal goroutines not
stopping if the harvester Setup() fails, for example when files cannot
be read.

Fixes elastic#6797
@ph
Copy link
Contributor

ph commented May 17, 2018

@adriansr I think we forgot to backport it to 6.2 is that possible?

@adriansr
Copy link
Contributor Author

@ph so it seems :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants