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

[JS scripting engine] Memory Leak #11952

Closed
egoist6 opened this issue Jan 3, 2022 · 6 comments · Fixed by openhab/openhab-core#2681 or #12022
Closed

[JS scripting engine] Memory Leak #11952

egoist6 opened this issue Jan 3, 2022 · 6 comments · Fixed by openhab/openhab-core#2681 or #12022
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@egoist6
Copy link

egoist6 commented Jan 3, 2022

As per digitaldan's request I re-open this ticket here which seems to be related to JSscripting.
When changing and testing JS scripts (edition 11) which have syntax errors, after 10-20 runs the CPU load increases to 100% and you get the following error messages:
2021-12-29 22:12:59.868 [WARN ] [org.eclipse.jetty.server.HttpChannel] - /rest/rules/SystemReadLog java.lang.OutOfMemoryError: Java heap space
2021-12-29 22:14:35.128 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@16f740b' takes more than 5000ms.
2021-12-29 22:19:26.790 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception: java.lang.OutOfMemoryError: Java heap space

Let me be more precise: at least the memory leak can be reproduced with faulty JS scripts - I am not saying that the script engine is the root cause of the poblem. I just wanted to bring this to your attention.

This problem has been confirmed by a couple of users yet.
See here
and here

Environment
latest openhab 3.2 and Zulu11-32 version installed by latest openhabian update option
Raspberry Pi4

@egoist6 egoist6 added the bug An unexpected problem or unintended behavior of an add-on label Jan 3, 2022
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/javascript-memory-stability-issues/130810/13

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/jsscripting-error-message-java-lang-outofmemoryerror-java-heap-space/130846/30

@jpg0
Copy link
Contributor

jpg0 commented Jan 11, 2022

Just leaving a note here:

From a small investigation I could not see anything in openHAB code which appears to leak upon repeated script load failure.

One possible source of leaking could be from inside Graal itself, because the engines (and hence the polyglot contexts) are not being closed (ScriptEngine.close()). The best place to put this is probably the ScriptEngineManagerImpl in core, as it's currently possible to repeatedly load one script which will overwrite the previous load without ever attempting to unload it (which is probably where it should be closed, if AutoCloseable).

@jpg0
Copy link
Contributor

jpg0 commented Jan 11, 2022

I have verified that the leak is due to my guess. Well, I repeatedly reloading an erroring script and did managed to push up the memory (by about 25%, although I couldn't get it any higher), however my closing engines I could not increase it at all.

This requires changes in both core and the add-on. The core change is openhab/openhab-core#2681

@jpg0
Copy link
Contributor

jpg0 commented Jan 11, 2022

The other change required is: #12022

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-becomes-unstable-and-slow-after-ecma-11-rule-coding-errors/132506/2

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
3 participants