-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[velux] Fix synchronisation of handler initialization and disposal #10449
Conversation
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@gs4711 feedback appreciated |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/velux-new-openhab2-binding-feedback-welcome/32926/1261 |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Are your sure to remove the synchronized of the dispose method?
Hmm. I have never actually observed OH calling dispose() on the same class instance more than once. Also the dispose() method of the parent class (that is overridden) is not declared synchronized, so I suspect the creators of OH did not foresee multiple calls to be made. ?? The real problem that I am trying to address, is when OH calls dispose() on one (old) class instance, and initialize() on another newly created class instance for the same hub. That is why the Future<> get() is made to cross synchronise the two methods between two separate class instances that relate to the same Bridge (IP address). However, do you have a specific reason why it should be synchronized? |
Guenther, some more thoughts on this..
|
...nhab.binding.velux/src/main/java/org/openhab/binding/velux/internal/bridge/slip/SClogin.java
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go for it for the time being!
But, in fact, IMHO it should be fixed in the framework.
@gs4711 I have a question concerning a potential a problem also with the Velux_Binding_Handler class. During a jar reload I saw VeluxBindingHandler.initialize() being called before VeluxBridgeHandler.disposeScheduled() had completed (see log below) i.e. well before VeluxBridgeHandler.initializeScheduled() had completed. And since VeluxBindingHandler has Channels that depend on the state and quantity of the VeluxBridgeHandler's Channels, I think its call to updateVisibleInformation() might also interfere with the disposal and re-initialization sequence of the respective Bridges. Or?? So I think I should also defer the execution of VeluxBindingHandler.initialize() (resp. updateVisibleInformation()) until all of the respective Bridges have been cleanly disposed and re-initialized? What do you think?
|
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
No, it does not actually interfere with the disposal and re-initialization. However the Velux Binding Handler Thing(s) display the wrong information because the respective Velux Bridge Handler Thing(s) have not had time to fully discover all their Things.
My last three commits defer the binding information update until after the Bridges & Things are disposed and re-initialized. |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
...ding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBindingHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewfg Thanks for your refactoring here.
Looking at the code, I noticed that there are still many info logs that should indeed be debug level instead. I see that they were in there before, but as you cleaned up the logging, it would be nice if you could address those, too.
Signed-off-by: Andrew Fiddian-Green <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the log levels!
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
...nding.velux/src/main/java/org/openhab/binding/velux/internal/handler/VeluxBridgeHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <[email protected]>
We have tried this. But Velux won't even answer the emails. They say it is provided "as is".. |
Yes I know that; and I can see it in my tests; in my case 'stop' takes about 15 seconds; whereby I have 17 bindings, and I am not sure if the delay is due to the Velux or something else.. Anyway, let me think about this overnight, and I will eventually push another change. I will ping you back when I am done. |
… timeout explicit; disable HSM on shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]>
I made another commit just now with the following changes..
@fwolter I have tested start/ stop combinations of a) OH itself, b) the binding, and c) specific bridges, so I think you can complete your review of the new code now if you want. But notwithstanding this I set the 'Additional Testing Required' flag, so I can let it run for a few days in my live system; so please don't actually merge the PR until I clear that flag again. |
@gs4711 this might (finally) be the key that resolves the 'zombie socket' problem. => What do you think? |
…M shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@fwolter I have been pressure testing this for a few days now, and it is all good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…penhab#10449) * [velux] break on socket timeout if interrupted flag set Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] pause initialize until pending dispose is done Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synchronization key is IP address not ThingUID Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level, improve user comprehensibility Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] access updateBindingState() externally via static method Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] tweak logging Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] defer refreshBindingInfo until after initialized / disposed Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] refactor method names to show the type of scheduler they run on Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't terminate thread early Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] restore calls to updateBindingState Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] logger cosmetics Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging levels Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] change logger level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synch on ip address object instead of Future<>; make shutdown timeout explicit; disable HSM on shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] add lock modifier, remove duplicate synchronized, refactor HSM shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] shutdown code was not being called Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't convert InterruptedException to IOException Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] let shutdown explicity stop the polling loop Signed-off-by: Andrew Fiddian-Green <[email protected]> Signed-off-by: John Marshall <[email protected]>
…penhab#10449) * [velux] break on socket timeout if interrupted flag set Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] pause initialize until pending dispose is done Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synchronization key is IP address not ThingUID Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level, improve user comprehensibility Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] access updateBindingState() externally via static method Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] tweak logging Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] defer refreshBindingInfo until after initialized / disposed Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] refactor method names to show the type of scheduler they run on Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't terminate thread early Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] restore calls to updateBindingState Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] logger cosmetics Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging levels Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] change logger level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synch on ip address object instead of Future<>; make shutdown timeout explicit; disable HSM on shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] add lock modifier, remove duplicate synchronized, refactor HSM shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] shutdown code was not being called Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't convert InterruptedException to IOException Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] let shutdown explicity stop the polling loop Signed-off-by: Andrew Fiddian-Green <[email protected]>
…penhab#10449) * [velux] break on socket timeout if interrupted flag set Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] pause initialize until pending dispose is done Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synchronization key is IP address not ThingUID Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level, improve user comprehensibility Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] access updateBindingState() externally via static method Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] tweak logging Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] defer refreshBindingInfo until after initialized / disposed Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] refactor method names to show the type of scheduler they run on Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't terminate thread early Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] restore calls to updateBindingState Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] logger cosmetics Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging levels Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] change logger level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synch on ip address object instead of Future<>; make shutdown timeout explicit; disable HSM on shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] add lock modifier, remove duplicate synchronized, refactor HSM shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] shutdown code was not being called Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't convert InterruptedException to IOException Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] let shutdown explicity stop the polling loop Signed-off-by: Andrew Fiddian-Green <[email protected]>
…penhab#10449) * [velux] break on socket timeout if interrupted flag set Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] pause initialize until pending dispose is done Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synchronization key is IP address not ThingUID Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level, improve user comprehensibility Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] access updateBindingState() externally via static method Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] tweak logging Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] defer refreshBindingInfo until after initialized / disposed Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] refactor method names to show the type of scheduler they run on Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't terminate thread early Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] restore calls to updateBindingState Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] logger cosmetics Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging levels Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] change logger level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synch on ip address object instead of Future<>; make shutdown timeout explicit; disable HSM on shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] add lock modifier, remove duplicate synchronized, refactor HSM shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] shutdown code was not being called Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't convert InterruptedException to IOException Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] let shutdown explicity stop the polling loop Signed-off-by: Andrew Fiddian-Green <[email protected]>
…penhab#10449) * [velux] break on socket timeout if interrupted flag set Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] pause initialize until pending dispose is done Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synchronization key is IP address not ThingUID Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging level, improve user comprehensibility Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] access updateBindingState() externally via static method Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] tweak logging Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] defer refreshBindingInfo until after initialized / disposed Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] refactor method names to show the type of scheduler they run on Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't terminate thread early Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] restore calls to updateBindingState Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] logger cosmetics Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] reduce logging levels Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] change logger level Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] synch on ip address object instead of Future<>; make shutdown timeout explicit; disable HSM on shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] add lock modifier, remove duplicate synchronized, refactor HSM shutdown Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] shutdown code was not being called Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] don't convert InterruptedException to IOException Signed-off-by: Andrew Fiddian-Green <[email protected]> * [velux] let shutdown explicity stop the polling loop Signed-off-by: Andrew Fiddian-Green <[email protected]>
The Velux hub initialization and shutdown processes are very slow and deliberate. And sometimes when OH reloads the binding, it was possible for a newly created
VeluxBridgeHandler
instance's.initialize()
method to be called before the priorVeluxBridgeHandler
instance's.dispose()
method had finished processing i.e. it was attempting to shut down and re-start the hub communication at the same time!See this forum post
Therefore this PR introduces the following fixes resp. improvements:
.initialize()
/.dispose()
methods now defer slow processes to scheduled tasks, so the OH caller thread returns faster..initializeScheduled()
method now waits for the Future<> result of a prior.disposeScheduled()
(if any) before proceeding.Signed-off-by: Andrew Fiddian-Green [email protected]