I get several warnings from the MQTT binding when shutting down openHAB as shown below. The messages relate to HomeAssistantDiscovery, Homie300Discovery, and EspMilightHubDiscoveryService – which I do not use in anyway at all. Any idea what is going on here? And how to eliminate these messages? (Running OH 3.1.0-SNAPSHOT #2324 on a Pi-4)
.. [WARN] [..AbstractBrokerHandler] - Tried to unsubscribe .. but topic not registered for listener. Check discovery logic!
.. [WARN] [..AbstractBrokerHandler] - Tried to unsubscribe .. but topic not registered at all. Check discovery logic!
On the Broker Thing there is an option (in the UI check “Show Advanced” and it’s at the bottom) called “Enable Discovery”. Turn that toggle off and the warnings should go away. If not, file an issue on the binding as that is what that toggle is supposed to do, turn off auto discovery.
If you look at the warning, it’s complaining that it cannot unsubscribe from the discovery topics. So are you arguing that when OH is shutting down it shouldn’t unsubscribe from the topics but just end? That’s not very nice to the broker and will generate errors.
It’s not a work around. If you disable discovery you will not subscribe to those topics in the first place. Therefore there will be no reason to unsubscribe. But if you are using discovery, you need to unsubscribe from those topics in order to shutdown cleanly.
So it’s a fair bet that it does successfully subscribe (why should it not, even if no message ever comes) and the unsubscribing is probably messing up (let’s guess maybe everything is unsubscribed en-bloc before the discovery services get round to it).
@rossko57 having looked into the code, I think your hypothesis is correct; it looks as though there are three override classes (EspMilight, Homie, HomeAssistant) that extend from the “generic” class, so my guess is that the override classes are doing stuff themselves that the “generic” class is wrongly trying to clean up for them; so I have filed a new issue; but I have not yet had time to fix the code.
I made a tentative PR (see below) HOWEVER because of all the dependencies, it require a rebuild of the OH Core; and I don’t have the skills to do that; so the solution is not tested; hopefully someone else can pick up where I left off…
The broker doesn’t do the clean up on its own. It is the discovery service that tells the broker to cleanup, and in this case it is wrongly telling the broker to clean up subscriptions that it had never actually made.
So in other words, I think it is the duty of the disco service to behave properly (eat your own dog food), rather than expect the other module to catch its mistakes.