Skip to content

Conversation

@florian-h05
Copy link
Contributor

Currently, there are two issues:

When a ScriptRecord is cleared from the cache,
the ScriptTransformationService currently closes the ScriptEngine itself, without involving the ScriptEngineManager. If a transformation script is invoked again after it has been cleared from the scriptCache, the ScriptEngineManager::createScriptEngine call makes the ScriptEngineManager first remove the old engine from its internal "store", which includes invoking the scriptUnloaded hook. This invocation can cause an exception because the engine is already closed (by ScriptTransformationService) and hence function/method invocations inside the engine are not possible anymore.

Ff the engine implement Compilable, it is even closed two times by ScriptTransformationService, possibly causing an exception if the ScriptEngine doesn't handle multiple close() calls gracefully.

These issues are fixed by properly notifying the ScriptEngineManager when an engine should be removed and leaving the removal handling to the ScriptEngineManager.

The issues were discovered while working on #5062.

Currently, there are two issues:

When a ScriptRecord is cleared from the cache,
the ScriptTransformationService currently closes the ScriptEngine itself, without involving the ScriptEngineManager.
If a transformation script is invoked again after it has been cleared from the scriptCache, the ScriptEngineManager::createScriptEngine call makes the ScriptEngineManager first remove the old engine from its internal "store",
which includes invoking the scriptUnloaded hook. This invocation can cause an exception because the engine is already closed (by ScriptTransformationService) and hence function/method invocations inside the engine are not possible anymore.

Ff the engine implement Compilable, it is even closed two times by ScriptTransformationService, possibly causing an exception if the ScriptEngine doesn't handle multiple close() calls gracefully.

These issues are fixed by properly notifying the ScriptEngineManager when an engine should be removed and leaving the removal handling to the ScriptEngineManager.

The issues were discovered while working on openhab#5062.

Signed-off-by: Florian Hotze <[email protected]>
@florian-h05 florian-h05 requested a review from a team as a code owner October 7, 2025 22:01
@florian-h05 florian-h05 changed the title ScriptTransformationService: Fix engine closed too early ScriptTransformationService: Handle engine removal through ScriptEngineManager Oct 7, 2025
Signed-off-by: Florian Hotze <[email protected]>
@florian-h05 florian-h05 force-pushed the script-transform-close branch from 8e1572b to 95ae1ba Compare October 8, 2025 11:05
Copy link
Contributor

@Nadahar Nadahar left a comment

Choose a reason for hiding this comment

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

LGTM

@kaikreuzer kaikreuzer merged commit 26015ff into openhab:main Oct 10, 2025
4 checks passed
@kaikreuzer kaikreuzer added the bug An unexpected problem or unintended behavior of the Core label Oct 10, 2025
@kaikreuzer kaikreuzer added this to the 5.1 milestone Oct 10, 2025
@florian-h05 florian-h05 deleted the script-transform-close branch October 10, 2025 23:50
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants