-
Notifications
You must be signed in to change notification settings - Fork 117
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
[FIXED] Reduce in-use memory space on connection close #252
Conversation
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
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.
🤔 So, I'm curious to hear what the actual reason for this not getting garbage collected was. In my test example, I had no reference to nc
, nor sc
, including no goroutines running that could hold a reference to any of these. Did you figure this out?
More of a thought, I just learnt that finalizers don't run on circular references, but I assume https://github.com/nats-io/go-nats-streaming/blob/3e2ff0719c7a6219b4e791e19c782de98c701f4a/stan.go#L452 has nothing to do with this? |
@JensRantil I could swear that this is the first thing I tried (commenting out the call to the finalizer), but I may have done something wrong because I could still see the issue. I then tried looking a the subs that were not unsubscribed on Anyway, with the test that I added and your test, removing the call to SetFinalizer() and looking at inuse_space, I can see that the problem is solved. The NATS Subscriptions have a reference to the NATS connection, and I think that without them being set to nil it would prevent the finalizer from running but would cause a reference to be held. Setting the subscriptions to nil I can see that the finalizer runs. Without setting them to nil, it does not run. But again, simply removing the finalizer works. So the question now is that: is the finalizer worth it? If not, I would gladly revert the changes and simply remove the call to finalizer. If we think it is worth having it, then the current fix is correct. @derekcollison, wdyt? |
I vote for removing the finalizer instead of breaking the circular reference. I've rarely seen a finalizer being needed and I'm not sure it's needed here since I suppose open files and sockets all have a finalizer on them to be closed anyway. |
Removing call to runtime.SetFinalizer() that was preventing resources from being released. Added a test to ensure that inuse memory does not grow when doing repeated Connect()/Close(). Resolves #251 Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Setting internal subscriptions and subMap to nil on subscription
close seem to eliminate the inuse_space report from go tool pprof
Resolves #251
Signed-off-by: Ivan Kozlovic ivan@synadia.com