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

Fix multiple leaks issues raised from CM #10567

Closed
wants to merge 5 commits into from
Closed

Conversation

ph
Copy link
Contributor

@ph ph commented Feb 5, 2019

Leaks:

  • Fix a goroutine leak when the output was updated, the old goroutine was
    blocked on waiting for events.

  • Fix an transport goroutine leak waiting on Reader, because of keep
    alive.

  • Fix a FD leaks from the elasticsearch output, output were replaced but
    the transport were not GC correctly and was keeping an ever increasing
    number of fd open.

Fixes: #10491

@ph ph requested a review from a team as a code owner February 5, 2019 13:51
@ph ph added Management needs_backport PR is waiting to be backported to other branches. labels Feb 5, 2019
@ph
Copy link
Contributor Author

ph commented Feb 5, 2019

Backport to 6.6

@@ -718,6 +718,8 @@ func (p *Input) Wait() {

// Stop stops all harvesters and then stops the input
func (p *Input) Stop() {
defer logp.Debug("input", "Log input stopped")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense to keep a trace of that when debugging why events are not going through..

@ph ph added the review label Feb 5, 2019
@ph ph assigned urso Feb 5, 2019
@ph ph requested a review from urso February 5, 2019 14:03

if t, ok := http.Transport.(ci); ok {
t.CloseIdleConnections()
}
Copy link

Choose a reason for hiding this comment

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

btw, an interface cast with one method can also be written like this:

if t, ok := http.Transport.(interface{ CloseIdleConnections() }); ok {
  t.CloseIdleConnections()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice trick I didn't know that.

}

return reflect.DeepEqual(a, b)
return true, nil
Copy link

@urso urso Feb 5, 2019

Choose a reason for hiding this comment

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

I wonder why golint or go vet do not complain here, but: return aHash == bHash, nil.

Still, I'd prefer proper equality checks over a hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer a hash in the long term, especially if we could diminish the roundtrip of call, I would be OK to implement our own hashing strategies later, I think for know hashstructure's Hash is an OK solution and would take care of a few false positive refresh.

@ph
Copy link
Contributor Author

ph commented Feb 5, 2019 via email

}

err := w.client.Publish(batch)
if err != nil {
logp.Err("Failed to publish events: %v", err)
// on error return to connect loop
break
connected = false
}
}
}
Copy link
Contributor Author

@ph ph Feb 5, 2019

Choose a reason for hiding this comment

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

The above does the following:

  1. make the close sync with the run() method.
  2. Closing the client will only happen when run() execution is completed.
  3. We check for <- w.done in two select, we do this to prioritize shutdown vs reading from queue on next execution loop, we also select on both the queue and the done channels and wait, first read will win here.

@ph
Copy link
Contributor Author

ph commented Feb 5, 2019

I have extracted the config equal change in #10587

Leaks:

- Fix a goroutine leak when the output was updated, the old goroutine was
blocked on waiting for events.

- Fix an transport goroutine leak waiting on Reader, because of keep
alive.

- Fix a FD leaks from the elasticsearch output, output were replaced but
the transport were not GC correctly and was keeping an ever increasing
number of fd open.
@ph
Copy link
Contributor Author

ph commented Feb 6, 2019

closing in favor of #10599

@ph ph closed this Feb 6, 2019
@ph ph removed needs_backport PR is waiting to be backported to other branches. labels Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Libbeat output reloading cause a goroutine leak and a possibly a fd leak
3 participants