eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
862 stars 783 forks source link

Karaf not stopping threads upon removing a bundle #5551

Open kgoderis opened 6 years ago

kgoderis commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 5 years ago

Hi, what about it issue?

ppieczul commented 5 years ago

Would that be some hint: https://github.com/eclipse/smarthome/pull/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 commented 5 years ago

This code base is unmaintained and has been migrated. See: https://github.com/eclipse/smarthome/pull/6883