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 memory leak. #2892

Merged
merged 1 commit into from
Aug 2, 2019
Merged

Fix memory leak. #2892

merged 1 commit into from
Aug 2, 2019

Conversation

klizhentas
Copy link
Contributor

This commit fixes memory leak in the cache module:

  • Cache calls in to create a NewWatcher
  • NewWatcher gets registered in the backend
  • Cache closes the watcher
  • Watcher never gets deleted from the backend
    fanout internal structure.

This is a defect in the way watchers are implemented:
closing a watcher should result from it's removal
from the fanout internal circular buffer prefix tree.

c.Lock()
defer c.Unlock()
if watcher == nil {
c.Warningf("Internal logic error: %v.", trace.DebugReport(trace.BadParameter("empty watcher")))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what trace.DebugReport(trace.BadParameter("empty watcher")) achieves here - looks like it'd be the same as just

c.Warning("Internal logic error: empty watcher")

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shows the trace

c.Warningf("Internal logic error: %v.", trace.DebugReport(trace.BadParameter("empty watcher")))
return
}
log.Debugf("Removed watcher %p via external close.", watcher)
Copy link
Collaborator

Choose a reason for hiding this comment

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

c.Debugf?

// or asyncronously, used in prod, to avoid potential deadlocks
func (w *BufferWatcher) closeAndRemove(sync bool) error {
w.closeWatcher()
if removeSync {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will always evaluate to true because removeSync is a constant defined above. Did you mean if sync here?

w.cancel()
return nil
}

const (
removeSync = true
removeAsync = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing this should actually be false (judging by how it's used and the function below).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 good catch!

This commit fixes memory leak in the cache module:

* Cache calls in to create a NewWatcher
* NewWatcher gets registered in the backend
* Cache closes the watcher
* Watcher never gets deleted from the backend
fanout internal structure.

This is a defect in the way watchers are implemented:
closing a watcher should result from it's removal
from the fanout internal circular buffer prefix tree.
@klizhentas klizhentas merged commit a5e9762 into branch/4.0 Aug 2, 2019
@zmb3 zmb3 deleted the sasha/memleak branch September 9, 2022 18:35
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.

3 participants