-
Notifications
You must be signed in to change notification settings - Fork 719
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
Conversation
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).
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.
LGTM
@@ -208,6 +208,7 @@ func (d *defaultDriver) Reconcile( | |||
*min, | |||
caCert, | |||
) | |||
defer esClient.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.
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.
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.
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.).
Unfortunately it's hard to create a unit/integration test for this. |
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.
Still LGTM
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.