Skip to content

Conversation

@mherwege
Copy link
Contributor

@mherwege mherwege commented Sep 10, 2025

If an item has no values persisted, the lastUpdate, lastChange and previousState persistence extensions could get into an infinite loop. This could also happen when the query to the persistence service fails when called from these extension methods, e.g. because the database is offline.

Resolves openhab/openhab-addons#19313

See https://community.openhab.org/t/high-cpu-usage-since-upgrade-to-5-0-1/165989/20?u=mherwege
See https://community.openhab.org/t/high-cpu-usage-when-calling-lastupdate-on-offline-influxdb-database/166198

Also see https://community.openhab.org/t/averagesince-calculation-wrong-if-no-measurements-in-timerange-available/166177/12. This PR adds some tests that look for the described behaviour in the community post. The tests did not reveal the issue so far.

If accepted, this should be backported.

@Nadahar @jimtng FYI

Signed-off-by: Mark Herwege <[email protected]>
@mherwege mherwege requested a review from a team as a code owner September 10, 2025 16:17
@Nadahar
Copy link
Contributor

Nadahar commented Sep 10, 2025

I'd say that this is a pretty important fix, so it should get priority.

Copy link
Member

@holgerfriedrich holgerfriedrich left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@holgerfriedrich holgerfriedrich added the bug An unexpected problem or unintended behavior of the Core label Sep 10, 2025
@holgerfriedrich holgerfriedrich added this to the 5.1 milestone Sep 10, 2025
@holgerfriedrich holgerfriedrich merged commit 31b43bc into openhab:main Sep 10, 2025
5 checks passed
holgerfriedrich pushed a commit that referenced this pull request Sep 10, 2025
* fix potential eternal loop on empty peristence
* tests

Signed-off-by: Mark Herwege <[email protected]>
@holgerfriedrich holgerfriedrich added the backported A PR that has been cherry-picked to a patch release branch label Sep 10, 2025
@holgerfriedrich
Copy link
Member

Merged an backported to 5.0.x. Not sure what to do with 4.3 - the code seems to be same there. I have not checked if tests make sense on 4.3.x.

@mherwege mherwege deleted the persistence_loop branch September 10, 2025 19:43
@mherwege
Copy link
Contributor Author

mherwege commented Sep 10, 2025

Merged an backported to 5.0.x. Not sure what to do with 4.3 - the code seems to be same there. I have not checked if tests make sense on 4.3.x.

I doubt back porting the tests makes much sense. There had been change to the code between 4.3 and 5.0 in this area, so back porting the fix will have to be a new PR against 4.3. The offending code had been there for more than 3 years already. So, should I do it?

@Nadahar
Copy link
Contributor

Nadahar commented Sep 10, 2025

So, should I do it?

With an issue like this, I'd say: absolutely. Just drop the tests and backport the fix.

@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/high-cpu-usage-when-calling-lastupdate-on-offline-influxdb-database/166198/3

@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/high-cpu-usage-since-upgrade-to-5-0-1/165989/31

@holgerfriedrich holgerfriedrich added the backported4 A PR that has been cherry-picked to 4.3.x series after release of OH5 label Sep 14, 2025
@holgerfriedrich
Copy link
Member

I'll label this as backported4 although this is done via separate PR #5019 (w/o the tests introduced for 5.x).

@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/postgres-runs-into-fatal-sorry-too-many-clients-already-almost-every-night/166827/3

@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/high-cpu-load-unresponsive-oh-since-upgrade-even-with-5-0-2/167055/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported A PR that has been cherry-picked to a patch release branch backported4 A PR that has been cherry-picked to 4.3.x series after release of OH5 bug An unexpected problem or unintended behavior of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[influxdb] High cpu usage when calling lastUpdate on offline InfluxDB database.

4 participants