-
Notifications
You must be signed in to change notification settings - Fork 80
Disallow soft references in MemoryAssert-related tests in FlowExecutionListTest
#437
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
Conversation
| // Make sure ForkJoinPool is not initialized on a thread where its inheritedAccessControlContext would point to a CpsGroovyShell$CleanGroovyClassLoader | ||
| ForkJoinPool.commonPool().execute(() -> {}); |
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.
It's a bit interesting that I keep running into these cases where first-time initialization of various objects happening in the context of a Pipeline build causes problems. In practice it's probably ok, and at worst they would only cause 1-build leaks, but I wonder how many such leaks are actually possible.
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.
There is a class loader sanity executor service wrapper in Jenkins core which should probably be used.
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.
Maybe, but this is the common pool, which seems to be unconfigurable, and the reference path was not via Thread.contextClassLoader as is typical (AppClassLoader in this case), but Thread.inheritedAccessControlContext, which holds a reference to CpsGroovyShell$CleanGroovyClassLoader via a ProtectionDomain.classloader, constructed I think via AccessController.getContext().
So whatever the exact problem is, it will go away once we pick up JEP 486 (Java 24+), which deletes Thread.inheritedAccessControlContext.
FWIW also I think the critical usage path of the common pool is via the default executor in Caffeine caches, specifically two caches in SimpleXStreamFlowNodeStorage and one in EnumeratingWhitelist. We could perhaps set their executors to Computer.threadPoolForRemoting or some manually-constructed thread pool to avoid the issue in the meantime.
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.
Ah yes, we ought to define a specific pool for use from Caffeine if possible. Ultimately using virtual threads (21+), though we might need to wait for monitor support in 24, and some diagnosability issues remain.
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.
The notable thing in these cases is that we are not obviously using any async-related methods or types with the Caffeine caches. We only use weakKeys, strongValues, and LoadingCache, so the fact that an async task is being submitted to the common pool is not immediately obvious. Perhaps it has to do with the internal maintenance referred to in the Javadoc.
While looking for places to test jenkinsci/jenkins-test-harness#1029, I noticed that this class was allowing soft references while using
MemoryAssert.assertGC, so I tracked them down and cleaned them out so the test can run with soft references disallowed.Testing done
See updated tests.
Submitter checklist