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

Prevent infinite loop in CronAdjuster with invalid date combinations #4548

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

jimtng
Copy link
Contributor

@jimtng jimtng commented Jan 9, 2025

Fix one of the problems in #4547

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@jimtng jimtng requested a review from a team as a code owner January 9, 2025 04:18
@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/rule-engine-not-running-although-bundle-active/161517/13

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.

Deploying this into my test system, an invalid cron expression still results in an ugly stack trace.
IllegalArgumentException - this exception is not properly handled in caller class.

Though, the PR prevents from an infinite loop, allows the system to reach startlevel 100. And it gives users a hint what is wrong.
So, I will merge this right now.

See the output of the test with invalid cron expression "0 0 0 31 2 *":

00:24:49.084 [ERROR] [core.common.registry.AbstractRegistry] - Cannot inform the listener "org.openhab.core.automation.internal.RuleEngineImpl$2@582e4c85" about the "ADDED" event: Cron expression '0 0 0 31 2 *' is not valid, too many restarts
java.lang.IllegalArgumentException: Cron expression '0 0 0 31 2 *' is not valid, too many restarts
        at org.openhab.core.scheduler.CronAdjuster.adjustInto(CronAdjuster.java:537) ~[?:?]
        at java.time.ZonedDateTime.with(ZonedDateTime.java:1245) ~[?:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.schedule(SchedulerImpl.java:174) ~[?:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.schedule(SchedulerImpl.java:168) ~[?:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.schedule(SchedulerImpl.java:160) ~[?:?]
        at org.openhab.core.internal.scheduler.DelegatedSchedulerImpl.schedule(DelegatedSchedulerImpl.java:97) ~[?:?]
        at org.openhab.core.internal.scheduler.CronSchedulerImpl.schedule(CronSchedulerImpl.java:73) ~[?:?]
        at org.openhab.core.internal.scheduler.CronSchedulerImpl.schedule(CronSchedulerImpl.java:61) ~[?:?]
        at org.openhab.core.automation.internal.module.handler.GenericCronTriggerHandler.scheduleJob(GenericCronTriggerHandler.java:71) ~[?:?]
        at org.openhab.core.automation.internal.module.handler.GenericCronTriggerHandler.setCallback(GenericCronTriggerHandler.java:67) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.lambda$0(RuleEngineImpl.java:635) ~[?:?]
        at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.register(RuleEngineImpl.java:632) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.activateRule(RuleEngineImpl.java:857) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.setRule(RuleEngineImpl.java:505) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.addRule(RuleEngineImpl.java:465) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl$2.added(RuleEngineImpl.java:275) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl$2.added(RuleEngineImpl.java:1) ~[?:?]
        at org.openhab.core.common.registry.AbstractRegistry.notifyListeners(AbstractRegistry.java:378) ~[?:?]
        at org.openhab.core.common.registry.AbstractRegistry.notifyListenersAboutAddedElement(AbstractRegistry.java:411) ~[?:?]
        at org.openhab.core.automation.internal.RuleRegistryImpl.notifyListenersAboutAddedElement(RuleRegistryImpl.java:252) ~[?:?]
        at org.openhab.core.automation.internal.RuleRegistryImpl.notifyListenersAboutAddedElement(RuleRegistryImpl.java:1) ~[?:?]
        at org.openhab.core.common.registry.AbstractRegistry.added(AbstractRegistry.java:175) ~[?:?]
        at org.openhab.core.automation.internal.RuleRegistryImpl.added(RuleRegistryImpl.java:414) ~[?:?]
        at org.openhab.core.automation.internal.RuleRegistryImpl.added(RuleRegistryImpl.java:1) ~[?:?]
        at org.openhab.core.common.registry.AbstractRegistry.added(AbstractRegistry.java:1) ~[?:?]
        at org.openhab.core.model.rule.runtime.internal.DSLRuleProvider.lambda$5(DSLRuleProvider.java:458) ~[?:?]
        at java.util.ArrayList.forEach(ArrayList.java:1596) ~[?:?]
        at org.openhab.core.model.rule.runtime.internal.DSLRuleProvider.lambda$3(DSLRuleProvider.java:458) ~[?:?]
        at java.util.ArrayList.forEach(ArrayList.java:1596) ~[?:?]
        at org.openhab.core.model.rule.runtime.internal.DSLRuleProvider.notifyProviderChangeListeners(DSLRuleProvider.java:450) ~[?:?]
        at org.openhab.core.model.rule.runtime.internal.DSLRuleProvider.modelChanged(DSLRuleProvider.java:176) ~[?:?]
        at org.openhab.core.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:298) ~[?:?]
        at org.openhab.core.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:138) ~[?:?]
        at org.openhab.core.model.core.internal.folder.FolderObserver.checkPath(FolderObserver.java:255) ~[?:?]
        at org.openhab.core.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:314) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl$Listener.notify(WatchServiceImpl.java:293) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl.lambda$6(WatchServiceImpl.java:278) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[?:?]
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) ~[?:?]
        at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024) ~[?:?]
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[?:?]
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
        at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl.doNotify(WatchServiceImpl.java:278) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl.notifyListeners(WatchServiceImpl.java:271) ~[?:?]
        at org.openhab.core.internal.service.WatchServiceImpl.lambda$4(WatchServiceImpl.java:232) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) ~[?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:317) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.lang.Thread.run(Thread.java:1583) [?:?]

@holgerfriedrich holgerfriedrich merged commit a7b8c1a into openhab:main Jan 10, 2025
2 checks passed
@holgerfriedrich holgerfriedrich added this to the 5.0 milestone Jan 10, 2025
@holgerfriedrich holgerfriedrich added the bug An unexpected problem or unintended behavior of the Core label Jan 10, 2025
holgerfriedrich pushed a commit that referenced this pull request Jan 10, 2025
@holgerfriedrich holgerfriedrich added the patch A PR that has been cherry-picked to a patch release branch label Jan 10, 2025
@jimtng jimtng deleted the cronadjuster branch January 11, 2025 00:28
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 the Core patch A PR that has been cherry-picked to a patch release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants