-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fix memory leak. #2892
Conversation
c.Lock() | ||
defer c.Unlock() | ||
if watcher == nil { | ||
c.Warningf("Internal logic error: %v.", trace.DebugReport(trace.BadParameter("empty watcher"))) |
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.
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")
?
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.
shows the trace
lib/backend/buffer.go
Outdated
c.Warningf("Internal logic error: %v.", trace.DebugReport(trace.BadParameter("empty watcher"))) | ||
return | ||
} | ||
log.Debugf("Removed watcher %p via external close.", watcher) |
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.
c.Debugf
?
lib/backend/buffer.go
Outdated
// or asyncronously, used in prod, to avoid potential deadlocks | ||
func (w *BufferWatcher) closeAndRemove(sync bool) error { | ||
w.closeWatcher() | ||
if removeSync { |
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 will always evaluate to true
because removeSync
is a constant defined above. Did you mean if sync
here?
lib/backend/buffer.go
Outdated
w.cancel() | ||
return nil | ||
} | ||
|
||
const ( | ||
removeSync = true | ||
removeAsync = true |
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'm guessing this should actually be false
(judging by how it's used and the function below).
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.
👍 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.
c2382c8
to
55f5418
Compare
This commit fixes memory leak in the cache module:
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.