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

[homekit] quick restart on network changes #12072

Merged
merged 4 commits into from
Jan 26, 2022
Merged

Conversation

yfre
Copy link
Contributor

@yfre yfre commented Jan 18, 2022

homekit binding makes currently a full restart on network changes like IP address changes.
the full restart includes removing all openhab items from the list of homekit accessories and adding them again. basically, the start/stop methods for binding start/stop were re-used

this could lead in some case to config reset in home all, like reported here
https://community.openhab.org/t/homekit-no-response-error-on-all-openhab-items/118200/172

this PR reduces the stop logic to minimum and especially skip the removal of homekit accessories on stop.

the changes are following:

  • slight rework on "start" function in order to remember the address the HomeKit was bound to
  • replace call of the standard "stop" function copy the few needed step to onChange function
  • add check to onChange function whether the removed address is the address HomeKit was bound to

Signed-off-by: Eugen Freiter freiter@gmx.de

Signed-off-by: Eugen Freiter <freiter@gmx.de>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/homekit-no-response-error-on-all-openhab-items/118200/175

@jlaur
Copy link
Contributor

jlaur commented Jan 19, 2022

Regression of #11720, looking at this might ease review.

@lolodomo lolodomo added the enhancement An enhancement or new feature for an existing add-on label Jan 19, 2022
@Sail-Away
Copy link

Some additional hints: in my logs I see that the reaction to short network interruptions is somewhat random. One event either causes no restart, one restart or two consecutive restarts. Looks like, depending on the actual timing, the network change listener either doesn't catch the event at all, or just one added or removed interface event, or both the removed and added events.

So would it make sense to add some debouncing?

Also, what I don't understand: why would we restart the bridge at all if the interface has just been removed, or if a different, unused network interface changes? Shouldn't a restart only be necessary if the used interface actually changes to a different address? However, this would make it necessary to evaluate the reoved and added, so it's not as straight forward as the current solution.

@yfre
Copy link
Contributor Author

yfre commented Jan 19, 2022

Some additional hints: in my logs I see that the reaction to short network interruptions is somewhat random. One event either causes no restart, one restart or two consecutive restarts. Looks like, depending on the actual timing, the network change listener either doesn't catch the event at all, or just one added or removed interface event, or both the removed and added events.

So would it make sense to add some debouncing?
not sure about this behaviour. my idea was to keep it the logic small and simple so that we can quickly restart on every event.

Also, what I don't understand: why would we restart the bridge at all if the interface has just been removed, or if a different, unused network interface changes? Shouldn't a restart only be necessary if the used interface actually changes to a different address? However, this would make it necessary to evaluate the reoved and added, so it's not as straight forward as the current solution.

good idea. it just one check which does not make it too complex but maybe reduce number of restart. added to PR

Signed-off-by: Eugen Freiter <freiter@gmx.de>
Signed-off-by: Eugen Freiter <freiter@gmx.de>
Signed-off-by: Eugen Freiter <freiter@gmx.de>
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo lolodomo merged commit ec93c36 into openhab:main Jan 26, 2022
@lolodomo lolodomo added this to the 3.3 milestone Jan 26, 2022
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Jan 28, 2022
* quick restart on network changes

* only restart if needed
* add null check

Signed-off-by: Eugen Freiter <freiter@gmx.de>
@Sail-Away
Copy link

Here's my first feedback after serveral days of testing (with a slightly modified code, as I also wanted to catch the added interfaces in the log; code can be found here). Really seems to be an improvement enhancing stability, had no issues so far.

Stopping and starting of the bridge now is skipped when an (anyway unused IPv6) interface gets removed or added, which happens quite often. Number of actual restarts thus is considerably reduced.

Actual restarts in case of a network interruption seem to behave well now, though accessories still get removed from the accessory list. This is due to the fact that on removing the interface all connections to subscribing devices get terminated, and in this case the SubscriptionManager unsubscribes all characteristics. However, as the restart of the bridge only is triggered by a second event when the network interface is added again, and this typically happens in the order of several seconds later, nothing gets messed up. To illustrate this, I copied a few lines from the log:
homekit_excerpt.log

Still I think that onChanged at least theoretically could be entered a second time before finishing the first time, as the network changes appear as separate events. So I wonder if it would make sense to lock onChanged (define it as synchronized).

One other small hint. I would change the log message
logger.trace("restarting HomeKit bridge on network interface changes.");
into something like
logger.trace("HomeKit bridge reacting on network interface changes.");,
as a call of onChanged now not necessarily leads to a restart.

@yfre
Copy link
Contributor Author

yfre commented Feb 3, 2022

@Sail-Away thank you a lot for testing and detailed feedback. it good to hear PR improves behaviour.

valid point with overlapping restarts and synchronized.
i will open new pull request for this.

@yfre
Copy link
Contributor Author

yfre commented Feb 4, 2022

@Sail-Away
here we go
#12205

volkmarnissen pushed a commit to volkmarnissen/openhab-addons that referenced this pull request Mar 3, 2022
* quick restart on network changes

* only restart if needed
* add null check

Signed-off-by: Eugen Freiter <freiter@gmx.de>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Apr 27, 2022
* quick restart on network changes

* only restart if needed
* add null check

Signed-off-by: Eugen Freiter <freiter@gmx.de>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
* quick restart on network changes

* only restart if needed
* add null check

Signed-off-by: Eugen Freiter <freiter@gmx.de>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
* quick restart on network changes

* only restart if needed
* add null check

Signed-off-by: Eugen Freiter <freiter@gmx.de>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
@yfre yfre deleted the light_restart branch November 15, 2022 21:51
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 for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants