-
-
Notifications
You must be signed in to change notification settings - Fork 15.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
Object cleaner implementation detail leaks #8017
Comments
@mosesn @bryce-anderson @ejona86 @carl-mastrangelo @trustin I would be interested in your take related to this one... |
Some ideas: maybe the ThreadFactory for the cleaner can be provided by the user? |
Has this become an issue now because Recycler was converted to use ObjectCleaner to remove the finalizer? It doesn't sound like this is a case of FastThreadLocal needing Unfortunately there is no limit to the amount of time the thread may remain alive, because it requires a GC to be able to exit. Brainstorm:
|
It is not the recycler, we disable that in our default configuration and if we disable it in our tests it still fails thread leak control. Instead I think that it is from the fast thread locals. |
FastThreadLocal does use Cleaner. Not sure if I understand it all correctly, but isn't there a cyclic dependency between FastThreadLocal / InternalThreadLocalMap and Cleaner? Meaning the Cleaner task / thread for FastThreadLocal / InternalThreadLocalMap will never actually complete. |
I just got bit by something similar. In our internal tests we prevent certain types of tests from making threads to make them more reliable and make sure they run quickly. But using Seen with Netty 4.1.24.Final:
|
If (explicitly) shutting down a cleaner thread is a reasonable short-term solution to mitigate this, maybe just storing a static reference to a "currently running thread" from within I totally agree, though, that it's a long-term solution should probably allow users to opt-out from running cleaners threads in their tests/apps. |
Sorry I was busy with some other things at work so I had no time to think about this yet.... I will think a bit about this over the next days and then hopefully find a good solution next week (crossing fingers). That said I am not sure yet how to handle this atm as without the cleaner we may leak direct memory. |
Motivation: As discussed in netty#8017, ObjectCleaner leaks into the rest of the environment and interacts with checks in some testing environments. Modifications: Avoid using ObjectCleaner in FastThreadLocal when the extending class is ignoring removal notifications. Result: Reduced usage of ObjectCleaner, and when combined with disabling Recycler, may allow tests to run without ObjectCleaner being used.
Motivation: ObjectCleaner does start a Thread to handle the cleaning of resources which leaks into the users application. We should not use it in netty itself to make things more predictable. Modifications: - Remove usage of ObjectCleaner and use finalize as a replacement when possible. - Clarify javadocs for FastThreadLocal.onRemoval(...) to ensure its clear that remove() is not guaranteed to be called when the Thread completees and so this method is not enough to guarantee cleanup for this case. Result: Fixes #8017.
Motivation: ObjectCleaner does start a Thread to handle the cleaning of resources which leaks into the users application. We should not use it in netty itself to make things more predictable. Modifications: - Remove usage of ObjectCleaner and use finalize as a replacement when possible. - Clarify javadocs for FastThreadLocal.onRemoval(...) to ensure its clear that remove() is not guaranteed to be called when the Thread completees and so this method is not enough to guarantee cleanup for this case. Result: Fixes #8017.
Motivation: ObjectCleaner does start a Thread to handle the cleaning of resources which leaks into the users application. We should not use it in netty itself to make things more predictable. Modifications: - Remove usage of ObjectCleaner and use finalize as a replacement when possible. - Clarify javadocs for FastThreadLocal.onRemoval(...) to ensure its clear that remove() is not guaranteed to be called when the Thread completees and so this method is not enough to guarantee cleanup for this case. Result: Fixes #8017.
@jasontedor this should be resolved by #8064 and #8062. To make it short we do not use the |
Thanks @normanmaurer. We have successfully upgraded to 4.1.28.Final with none of the issues we had previously. 🙏 |
@jesty no... this class only existed in 4.1. |
ok, thanks. |
This is a follow on to the discussion in #8014. The problem here is that the object cleaner thread is considered an internal implementation detail yet its details can leak.
In Elasticearch, we have a thread leak control that detects threads created by a test suite but are not stopped at the end of the test suite. This is part of broader detection in our test framework for leaked resources of any kind.
The problem here is that because the object cleaner thread can not be stopped or otherwise controlled, it fails our thread leak control as it will always be running in nearly any test suite that interacts with Netty.
We tried to upgrade to Netty 4.1.25 and it was quite a mess because of this thread: elastic/elasticsearch#31232. We tried putting a filter in place on relevant test suites but we ultimately decided the surface area here is too large and this is gross anyway, especially without any public API guarantees about the thread. We have ultimately decided to revert this upgrade (elastic/elasticsearch#31282) and are now considering ourselves blocked on upgrading until a better solution to the object cleaner thread problem can be found.
We are looking for a way to shutdown the cleaner (ideally by adding something to our shutdown code (HTTP, TCP) so that all tests pick it up and it's not as messy as needing to filter the thread from leak control everywhere).
Alternatively, a way to avoid the use of the object cleaner would be acceptable too.
The text was updated successfully, but these errors were encountered: