-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix goroutine leak in SubOutlet #7820
Conversation
558a906
to
bca6f3f
Compare
filebeat/channel/util.go
Outdated
// still running. | ||
o.mutex.Lock() | ||
defer o.mutex.Unlock() | ||
o.closeEventChannel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused , we have a call to close(o.done)
this will trigger the select below and call o.closeEventChannel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The channel can still be close.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I got it,
OnEvent -> Acquire mutex
Out of bound close -> Block on mutex if on event is currently running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adriansr I am a bit worried that we add one more synchronization mechanism to this object, we have the isOpen (atomic bool), the chClosed
has some execution state, the mutex and the channels.
I think I am missing some context from the environment and I am just trying to understand what we want to prevent, it is multiple calls to `close(o.ch)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This mutex prevents the event channel to be closed if OnEvent is
// still running.
From your comment this is what we want to stop? So we could drop the atomic bool and use isOpen instead of chClosed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by "drop" I mean using a single mutex.
bca6f3f
to
6ef0446
Compare
I've submitted a simpler version addressing @ph comments. To my understanding, the atomic bool is still necessary to prevent closing done twice. |
I didn't examine the code but based on the sounds of it this could be a good use case for |
// still running. | ||
o.mutex.Lock() | ||
defer o.mutex.Unlock() | ||
close(o.ch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as @andrewkroh noted sync.Once
could replace the semaphore isOpen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The open flag is also used in OnEvent
. Once the outlet is closed, we MUST NOT run into the select block in OnEvent. A select
is non-deterministic. Even if o.done is closed, we might end up sending something to o.ch
. Depending on current state this can generate either a panic or some inconsistent state .
6ef0446
to
7aedaa5
Compare
7aedaa5
to
f7e73e8
Compare
This fixes a goroutine leaking every time that a harvester is closed.
f7e73e8
to
9bd463c
Compare
@adriansr I've look at the failure on the CI, I think its one of our flaky test.
@urso we can merge as is? WDYT? |
@ph just in case, I relaunched the failing job. Now it passed. |
@adriansr I've merged it, I will take a look as soon as possible to find why this test is not reliable. |
This fixes a goroutine leaking every time that a harvester is closed. (cherry picked from commit b84e083)
Cherry-pick of PR #7820 to 6.4 branch. Original message: This fixes a goroutine leaking every time that a harvester is closed.
This fixes a goroutine leaking every time that a harvester is closed. (cherry picked from commit b84e083)
This fixes a goroutine leaking every time that a harvester is closed. (cherry picked from commit b84e083)
Cherry-pick of PR #7820 to 6.5 branch. Original message: This fixes a goroutine leaking every time that a harvester is closed.
Cherry-pick of PR #7820 to 6.x branch. Original message: This fixes a goroutine leaking every time that a harvester is closed.
…stic#9592) Cherry-pick of PR elastic#7820 to 6.5 branch. Original message: This fixes a goroutine leaking every time that a harvester is closed.
…stic#7875) Cherry-pick of PR elastic#7820 to 6.4 branch. Original message: This fixes a goroutine leaking every time that a harvester is closed.
…stic#9592) Cherry-pick of PR elastic#7820 to 6.5 branch. Original message: This fixes a goroutine leaking every time that a harvester is closed.
This fixes a goroutine leaking every time that a harvester is closed.