Skip to content
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

[ARTEMIS-2171]: ThreadPoolExecutor leak under SM due to lack of privileged block. #2517

Closed
wants to merge 1 commit into from

Conversation

ehsavoie
Copy link
Contributor

  • Ensuring that all threadPoolFactories are created under a privileged
    block so the threads created are under the same AccessControlContext.

Jira: https://issues.apache.org/jira/browse/ARTEMIS-2171

…leged block.

* Ensuring that all threadPoolFactories are created under a privileged
block so the threads created are under the same AccessControlContext.

Jira: https://issues.apache.org/jira/browse/ARTEMIS-2171
@Override
public Thread newThread(Runnable r) {
return new Thread(r);
public ThreadFactory run() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this inst your change, but it highlights a bigger question, as to why is this not using ActiveMQThreadFactory?

As this creates threads with the captured context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because i looked at all threadFactories that werre not protected, didn't check the implementation. Sorry for this noise on ActiveMQThreadFactory

return AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {
@Override
public ActiveMQThreadFactory run() {
return new ActiveMQThreadFactory(this.getClass().getSimpleName() + "-scheduled-threads", false, getThisClassLoader());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threads created by ActiveMQThreadFactory should be already created by doPrivileged. how are we sure its not just that the thread issues you are seeing are maybe just where code isn't using ActiveMQThreadFactory

see in ActiveMQThreadFactory

   @Override
   public Thread newThread(final Runnable command) {
      // create a thread in a privileged block if running with Security Manager
      if (acc != null) {
         return AccessController.doPrivileged(new ThreadCreateAction(command), acc);
      } else {
         return createThread(command);
      }
   }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i said if you can supply a test with this PR to recreate the issue. then we can validate what does or what does not need to be changed.

E.g. if it is truely needed then may look to put the logic in one common place.

And like wise avoid future breakage should new code be added or existing refactored

The fact i believe wildfly has been using 1.5 of artemis without issue and the same thread factory is there. Its important that the issue is well understood, and avoid future regression

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I think the issue was initially reported against 1.5.x since it is almost year old but i don't have much details in the initial bug report.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot stress this enough. Test first please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to 'see' the issue within WildFly so I can provide a test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff.

thr.setContextClassLoader(moduleTccl);
return null;
public ThreadFactory run() {
return new ThreadFactory() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this inst your change, but it highlights a bigger question, as to why is this not using ActiveMQThreadFactory?

As this creates threads with the captured context.

@michaelandrepearce
Copy link
Contributor

This really needs a test case

A) validate the fix (and validate any alternative proposals)
B) ensure no regression

@@ -157,7 +157,12 @@ public NetworkHealthCheck parseURIList(String addressList) {

@Override
protected ActiveMQThreadFactory getThreadFactory() {
return new ActiveMQThreadFactory("NetworkChecker", "Network-Checker-", false, getThisClassLoader());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just creating a ThreadFactory.. is it really needed?

I would expect a security check around new Threads, but against a new ActiveMQThreadFactory?

are you sure about it? just checking it's not a typo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a test case on this. I think the issue might be we have some ThreadFactories which are not using the ActiveMQThreadFactory which should imo ensure the privileged access if its used in replacement for those, and actually we just need to fix those up. A test though is the best way for sure, so what ever fix, we know its resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We run WildFly test suite with a security manager on (which is how this leak was found) BUT I don't have the runs where this happened so I don't know the symptoms :( for a test ensure that this is resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we need a test in ActiveMQ Artemis for this to merge.

We need to be able to build, refactor, and release with knowing we haven't broken something our users and upstream/dependent projects have on us. Like wise we need to validate the fix.

essentially i suggest a test is created with a security manager on, in the activemq artemis project, with a similar leak detector to what youre doing in your project "wildfly" so to create this testing scenario in artemis.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the number of ActiveMQThreadFactory$1 increasing steadily without any activity on current master of WildFly with Artemis 2.6.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it on WildFly with 2.6.4 if I wait sufficiently for the polls to decrease

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the increase stops when the default size is reached so this doesn't look like an issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff theres no leak.

That issue of it increasing the pool to max even if idle should be resolved in next release 2.7.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehsavoie can you close this PR then? And the Jira you opened.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehsavoie please close this then.

@ehsavoie ehsavoie closed this Feb 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants