Skip to content

Comments

[roku] Fix jobs not starting if initial connection fails#20214

Open
mlobstein wants to merge 4 commits intoopenhab:mainfrom
mlobstein:roku_resolve
Open

[roku] Fix jobs not starting if initial connection fails#20214
mlobstein wants to merge 4 commits intoopenhab:mainfrom
mlobstein:roku_resolve

Conversation

@mlobstein
Copy link
Contributor

Follow-up to #20208
The previous changes have a problem where if the hostname resolution or initial connection request fails, then the scheduled jobs that poll the device will not be started. This MR corrects that and improves the hostname resolution so that it will re-try until successful. The redundant getDeviceInfo() call was also refactored to be done inside refreshPlayerState().

@realPyR3X, Please test if you can.

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
@mlobstein mlobstein requested a review from Copilot February 12, 2026 00:14
@mlobstein mlobstein added bug An unexpected problem or unintended behavior of an add-on regression Regression that happened during the development of a release. Not shown on final release notes. labels Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an initialization regression in the Roku binding where scheduled polling jobs could fail to start (or never recover) when initial hostname resolution/connection fails, by moving initialization responsibilities into the periodic refresh flow and retrying hostname resolution.

Changes:

  • Start automatic refresh and app-list refresh immediately during handler initialization (independent of initial connection success).
  • Add resolveHostName() and call it from refresh/command paths to retry hostname resolution until successful.
  • Refactor the initial getDeviceInfo() property population into refreshPlayerState() and gate it with deviceInfoLoaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 141 to 147
try {
resolvedHost = InetAddress.getByName(resolvedHost).getHostAddress();
communicator = new RokuCommunicator(httpClient, resolvedHost, port);
} catch (UnknownHostException e) {
logger.debug("Unable to resolve host", e);
logger.debug("Unable to resolve hostname", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Cannot resolve hostname");
} catch (RokuHttpException e) {
logger.debug("Unable to retrieve Roku device-info. Exception: {}", e.getMessage(), e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Cannot connect to device");
return false;
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

resolveHostName() updates Thing status to OFFLINE on every failed resolution attempt. Since it is called on each refresh/command, this can generate repeated status events and noisy logs while DNS is down. Consider only calling updateStatus(...) when the status/detail/message actually changes, and/or adding a retry backoff to resolution attempts.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFIAK it is not an issue to call updateStatus() with the same status repeatedly.

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends on if you see this as a transient or a permanent error.
I guess you could makt it as a configuration error and put the thing offline permanent until the configuration has been updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that it would be a transient error that would occur when the thing is started (system reboot in most cases) but the network is down preventing the hostname from being resolved. In that case it should re-try in the hopes that the network comes up. But of course it could also be due to an incorrectly entered host name in which case it would be permanent.

I just tested both scenarios and unfortunately the exception message is the same in each circumstance:

 java.net.UnknownHostException: No such host is known (roku)
         at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[?:?]
         ...

As such I don't think there is a readily available way to determine the nature of the error in this case.

Copy link
Contributor

@lsiepel lsiepel Feb 14, 2026

Choose a reason for hiding this comment

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

Ok, another question. What if the address is resolved and cached, but the DNS is changed at some point in time.
This will render the thing Offline, while all it should do is to resolve the host again. Currently the user needs to manually disable/enable the thing to get it resolved.

Fixing this might make it more complex and the current way of handling this might be a good tradeoff, but like to mention this before we move forward.

Copy link
Contributor Author

@mlobstein mlobstein Feb 14, 2026

Choose a reason for hiding this comment

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

That is a good point... I have a made a fix for that. But as I was going to commit, it occurred to me that this logic is getting very complex in the handler and it might be better to move all of this down into the communicator at the point of use. That would help maintain the separation of concerns. WDYT?

Edit: Made additional changes to do the resolution in the RokuCommunicator instead.

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
@realPyR3X
Copy link
Contributor

@mlobstein I tested this and confirmed everything works as expected on my end.

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

Just one waiting for the thing state discussion to conclude.

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An unexpected problem or unintended behavior of an add-on regression Regression that happened during the development of a release. Not shown on final release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants