Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Karaf not stopping threads upon removing a bundle #5551

Open
kgoderis opened this issue May 8, 2018 · 6 comments
Open

Karaf not stopping threads upon removing a bundle #5551

kgoderis opened this issue May 8, 2018 · 6 comments

Comments

@kgoderis
Copy link
Contributor

kgoderis commented May 8, 2018

When stopping or removing a bundle (e.g. from the add-ons folder) from Karaf, threads that are created by that bundle keep running and are not terminated. Sometimes end-users do upgrade bundles in running instances, and in doing so, duplicating threads could be the result, with various side effects and so forth. AFAIK none of the binding bundles implement a mechanism to stop lingering threads. One can take action in ThingHandler::dispose() to clean up resources, but when bundles are removed, then this is no helpful (I think).

A mechanism sh(c)ould be put in place to catches such threads or allow developers to clean up after such a removal.

One option would be to do something with ThingHandlerFactory::deactivate(); Another option could be to have ThingHandlers register the threads they create in a registry that is centrally controlled, or that is managed by the bundle's ThingHandlerFactory. Or have the all the threads run in a thread pool that is that is monitored by the core (which is just a question of defining coding guidelines I guess)

@sjsf
Copy link
Contributor

sjsf commented May 9, 2018

One can take action in ThingHandler::dispose()

No, bindings must do that! When bundles are stopped, their ThingHandlerRegistry gets removed. The framework detects that and disposes all its handlers. To ThingHandler.dispose() is called on all handlers.

It's clearly a bug in the binding if any threads and/or scheduled jobs are not cancelled properly after disposed() was called.

@kgoderis
Copy link
Contributor Author

kgoderis commented May 10, 2018

@SJKA Well, I am not sure what is happening then, because I do get rid of the threads in the dispose(), but somehow they keep running afterwards. Note, this is while deleting the .jar from the add-ons folder. I am not sure how that impacts the stopping of the bundle

@kaikreuzer
Copy link
Contributor

I am pretty sure that Karaf does a proper "bundle uninstall" when you remove the jar - I'd suggest to go through with the debugger to see whether dispose is called and why your threads keep running.

@spot62
Copy link

spot62 commented Jul 3, 2019

Hi, what about it issue?

@ppieczul
Copy link
Contributor

ppieczul commented Jul 3, 2019

Would that be some hint: #6636
I had the same issue in my binding with threads not finishing upon ending the thread method and had to add a new thread pool with timeout set to zero. Then it started to wind up correctly.

@maggu2810
Copy link
Contributor

This code base is unmaintained and has been migrated. See: #6883

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants