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

[fmiweather] Exception on startup #17668

Closed
jlaur opened this issue Oct 29, 2024 · 1 comment · Fixed by #17669
Closed

[fmiweather] Exception on startup #17668

jlaur opened this issue Oct 29, 2024 · 1 comment · Fixed by #17669
Assignees
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@jlaur
Copy link
Contributor

jlaur commented Oct 29, 2024

I have observed this exception in my logs during openHAB startup:

2024-10-28 20:45:30.497 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception: 
java.lang.IllegalStateException: Http client factory not available
	at org.openhab.core.io.net.http.HttpUtil.executeUrlAndGetReponse(HttpUtil.java:191) ~[?:?]
	at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:155) ~[?:?]
	at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:130) ~[?:?]
	at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:108) ~[?:?]
	at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:89) ~[?:?]
	at org.openhab.binding.fmiweather.internal.client.Client.queryWeatherStations(Client.java:161) ~[?:?]
	at org.openhab.binding.fmiweather.internal.discovery.FMIWeatherDiscoveryService.lambda$0(FMIWeatherDiscoveryService.java:74) ~[?:?]
	at org.openhab.core.cache.ExpiringCache.refreshValue(ExpiringCache.java:101) ~[?:?]
	at org.openhab.core.cache.ExpiringCache.getValue(ExpiringCache.java:72) ~[?:?]
	at org.openhab.binding.fmiweather.internal.discovery.FMIWeatherDiscoveryService.cachedStations(FMIWeatherDiscoveryService.java:193) ~[?:?]
	at org.openhab.binding.fmiweather.internal.discovery.FMIWeatherDiscoveryService.createObservationsForStations(FMIWeatherDiscoveryService.java:153) ~[?:?]
	at org.openhab.binding.fmiweather.internal.discovery.FMIWeatherDiscoveryService.createResults(FMIWeatherDiscoveryService.java:124) ~[?:?]
	at org.openhab.binding.fmiweather.internal.discovery.FMIWeatherDiscoveryService.lambda$1(FMIWeatherDiscoveryService.java:112) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
	at java.lang.Thread.run(Thread.java:833) [?:?]

Expected Behavior

Binding should not throw exception and discovery should work correctly.

Current Behavior

Bindings throws exception.

Possible Solution

As soon as the framework creates an instance of FMIWeatherDiscoveryService, a new Client is created:

private ExpiringCache<Set<Location>> stationsCache = new ExpiringCache<>(STATIONS_CACHE_MILLIS, () -> {
try {
return new Client().queryWeatherStations(STATIONS_TIMEOUT_MILLIS);
} catch (FMIUnexpectedResponseException e) {
logger.warn("Unexpected error with the response, potentially API format has changed. Printing out details",
e);
} catch (FMIResponseException e) {
logger.warn("Error when querying stations, {}: {}", e.getClass().getSimpleName(), e.getMessage());
}
// Return empty set on errors
return Collections.emptySet();
});

which is immediately queried:

public Set<Location> queryWeatherStations(int timeoutMillis)
throws FMIIOException, FMIUnexpectedResponseException, FMIExceptionReportException {
try {
String response = HttpUtil.executeUrl("GET", WEATHER_STATIONS_URL, timeoutMillis);

and core in return throws exception:

https://github.com/openhab/openhab-core/blob/728c7376b650c2c1cd271128f39d300cbacbf212/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/HttpUtil.java#L189-L192

The factory is set here:

https://github.com/openhab/openhab-core/blob/728c7376b650c2c1cd271128f39d300cbacbf212/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/HttpUtil.java#L539-L542

but apparently this has not yet happened during the startup.

Even though this might actually be a timing issue/bug in core, it could probably be mitigated in the binding by one of the following measures:

  • Delaying initialization of stationsCache until a scan has been started.
  • Using a more standard OSGi life cycle approach with HttpClient rather than the static HttpUtil class.

Steps to Reproduce

I'm not sure how easy it is to reproduce given that it's most likely a timing-related issue. However, I have seen it on multiple occasions during startup on my quite old development machine (running Windows).

Your Environment

  • Version used: 4.3 latest snapshot as of today
@jlaur jlaur added the bug An unexpected problem or unintended behavior of an add-on label Oct 29, 2024
@jlaur
Copy link
Contributor Author

jlaur commented Oct 29, 2024

I'll have a look at this, since I'm currently able to reproduce it more or less consistently each day.

@jlaur jlaur self-assigned this Oct 29, 2024
jlaur added a commit to jlaur/openhab-addons that referenced this issue Oct 29, 2024
Fixes openhab#17668

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
KaaNee pushed a commit to KaaNee/openhab-addons that referenced this issue Nov 8, 2024
Fixes openhab#17668

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
matchews pushed a commit to matchews/openhab-addons that referenced this issue Dec 16, 2024
Fixes openhab#17668

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant