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

Prevent shutdown of shared thread pool #2531

Merged
merged 1 commit into from
Nov 15, 2021
Merged

Conversation

janvyb
Copy link
Contributor

@janvyb janvyb commented Oct 19, 2021

Right now shared thread pools can be shut down, which leads to many problems (as described in #760 and #2465).

This PR fixes it by overriding shutdown and shutdownNow methods on wrapper classes around thread pools returned from factory methods on ThreadPoolManager, preventing shutdown and logging errors to help find out what addon calls them. This should not cause any issues since shared pools are never shut down by framework.

Closes #760

@janvyb janvyb requested a review from a team as a code owner October 19, 2021 18:10
@janvyb janvyb force-pushed the main branch 2 times, most recently from 5ec774f to e2f1b4f Compare October 19, 2021 18:27
@wborn wborn added rebuild Triggers the Jenkins PR build and removed rebuild Triggers the Jenkins PR build labels Oct 23, 2021
@kaikreuzer kaikreuzer added enhancement An enhancement or new feature of the Core rebuild Triggers the Jenkins PR build and removed rebuild Triggers the Jenkins PR build labels Oct 24, 2021
@kaikreuzer
Copy link
Member

The QueueingThreadPoolExecutor is in a public package and thus a part of the openHAB Core API. It might thus be used in other places than the ThreadPoolManager. Overwriting its methods and logging of warnings is therefore dangerous.

I'd see two options:

  1. Duplicate the class into an internal package and only change the internal one.
  2. Move the class to an internal package. This would hence be API breaking, but as far as I can tell, no official code in openHAB makes use of this class, so this might be acceptable.

@janvyb and @openhab/core-maintainers WDYT?

@janvyb
Copy link
Contributor Author

janvyb commented Oct 25, 2021

The QueueingThreadPoolExecutor is in a public package and thus a part of the openHAB Core API. It might thus be used in other places than the ThreadPoolManager. Overwriting its methods and logging of warnings is therefore dangerous.

Yeah, I can see that it might be a problem. How about creating another wrapper around ExecutorService and ScheduledExecutorService which would pass all methods to it's delegate except for shutdown and shutdownNow (something like Collections.unmodifiableList, but for schedulers), and then wrapping schedulers returned from methods on ThreadPoolManager?

@kaikreuzer
Copy link
Member

ExecutorService is an interface, not a class. So I guess you mean essentially that we could create a subclass of QueueingThreadPoolExecutor instead of duplicating it - yes, that's indeed much better than option 1 above.

@janvyb
Copy link
Contributor Author

janvyb commented Oct 26, 2021

What about this? It should be safe as long as noone cast the returned ExecutorService or ScheduledExecutorService into something else (which they should never do anyway). I'm not super happy about the wrapper's name but could not come up with anything better.

@kaikreuzer
Copy link
Member

Might work that way. But what was wrong about the idea to create an internal subclass of QueueingThreadPoolExecutor?

@janvyb
Copy link
Contributor Author

janvyb commented Oct 27, 2021

Might work that way. But what was wrong about the idea to create an internal subclass of QueueingThreadPoolExecutor?

I'd also have to create subclass of WrappedScheduledExecutorService since it's also being inserted into that pools hashmap inside getScheduledPool method. This way I don't have to care about specific implementation of ExecutorService or ScheduledExecutorService that's being returned.

@wborn wborn changed the title Prevent shutdown of shared thread pool (#760) Prevent shutdown of shared thread pool Oct 29, 2021
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

Alright, thank you!
Let's merge and see if it all works as expected :-)

@kaikreuzer kaikreuzer merged commit a328443 into openhab:main Nov 15, 2021
@kaikreuzer kaikreuzer added this to the 3.2 milestone Nov 15, 2021
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shutdown of Executors provided by ThreadPoolManager
3 participants