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

Close HTTP idle connections to prevent goroutines leak #855

Merged
merged 3 commits into from
May 15, 2019

Conversation

sebgl
Copy link
Contributor

@sebgl sebgl commented May 14, 2019

When either ES or process manager http clients go out of scope, make
sure we close idle keep-alive HTTP connections.

Otherwise, the underlying goroutines stay alive forever (with their heap).
Since we create new clients at every reconciliation iteration (and observer
iteration for the process manager), we end up provoking memory leaks,
leading to the operator being killed by k8s (OOM).

I manually tested that goroutine and memory leak does not occur anymore. See #854.

Fixes #854.

When either ES or process manager http clients go out of scope, make
sure we close keep-alive HTTP connections.

Otherwise, the underlying goroutines stay alive forever (with their heap),
provoking memory leaks
leading to the operator being killed by k8s (OOM).
Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -208,6 +208,7 @@ func (d *defaultDriver) Reconcile(
*min,
caCert,
)
defer esClient.Close()
Copy link
Contributor Author

@sebgl sebgl May 14, 2019

Choose a reason for hiding this comment

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

just realized one caveat of this approach is the client may be used by the observer (first iteration - not used in next iterations if no auth/cert change). No super big deal (idle connections closed, doesn't stop active ones), but this action still has an impact that is not immediately obvious.
I'll try to fix it so the observer client is a different one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed in next commit, by passing a different client to the observers.

If we use the same client that gets closed at the end of a
reconciliation, it would otherwise impact observers' client.

Note: most of the times, the client passed to the observer is not used.
Observer keeps using the same client it was created with unless the new
one is different (different certs, auth, etc.).
@sebgl
Copy link
Contributor Author

sebgl commented May 14, 2019

Unfortunately it's hard to create a unit/integration test for this.
I created #856 to include memory usage tracking in scale tests.

Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

Still LGTM

@sebgl sebgl merged commit a115b3e into elastic:master May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Goroutine leak
3 participants