-
Notifications
You must be signed in to change notification settings - Fork 820
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
[Test] Release unpooled buffer after usage to avoid leakage #862
[Test] Release unpooled buffer after usage to avoid leakage #862
Conversation
6ed1b1e
to
bc2c6e1
Compare
@@ -559,6 +559,7 @@ public void close() { | |||
// Update all not clean session with the proper expiry date | |||
updateNotCleanSessionsWithProperExpire(); | |||
queueRepository.close(); | |||
pool.values().forEach(Session::cleanUp); |
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.
When broker instance is shutdown, also all the reference counted objects kept live by inflight or qos2Receiving
(phase 2 of QoS2) need to be un-referenced, so that others Netty libraries doesn't expose buffer leakage when just the broker part is stopped.
fda7eaf
to
65d6154
Compare
Hi @hylkevds I ask if you could review this PR, you have previous experience with buffer leakage :-) |
Sure, I'll go over it. |
Man, finding buffer leaks in tests is annoying! At the time the leak warning pops up, there is no relation to the test that actually caused the leak! So I made a modified netty ResourceLeakDetector.java Then a search/replace on all tests. Multi-line regex Search (including final line ending):
replace:
And netty will tell the test that caused the resource leak:
Now to find the actual cause :) |
I've done manually 😄 by dissection, finding the minimal 2 or 3 tests that made the problem to trigger. |
Yep, I patched Netty and re-build the netty-common jar.
Maven then automatically picks up the patched version. The problem I had with running individual tests is that the garbage collection was never triggered, so the leak-detection also never triggered... |
Maybe it worthwhile to propose on the upstream Netty project, that hint would help also others, I think. |
I could not imagine Netty didn't already have something similar. The ResourceLeakDetector has something called Add this to Utils:
And then in each @test (using the search & replace):
And no need to patch Netty anymore! |
@hylkevds this is a good hint, it will deserve a follow up PR, if you want to contribute I'll be happy t review. Just a note, instead of using |
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.
Changes look good. There seems to be just one leak left to find.
65d6154
to
facc759
Compare
Release notes
[rn:skip]
What does this PR do?
Fix unpooled buffer leakage in tests.
Resolves leakage of Netty pooled buffers like in https://github.com/moquette-io/moquette/pull/872/checks#step:5:285