I have found a bug in Kotlin JSR-223 implementatio...
# scripting
v
I have found a bug in Kotlin JSR-223 implementation. When you want to precompile a script with bindings, you have to add bindings to engine scope first, which is ok. Later, when evaluating script with compiledScript.eval(bindings), Kotlin JSR-223 engine ignores those new bindings, and uses the ones from engine scope. I run multiple scripts in multiple threads sharing the same engine instance, using shared bindings from engine scope is not thread safe.
i
Please report the bug to Kotlin YouTrack. But I strongly recommend you to stop sharing an engine between threads. The kotlin engine keeps (in the engine scope bindings) the state of the compilation and evaluation, and although there is some locking in place, so it should not blow up, you may see some things leaking from one script to another. And compilation will be serialized anyway. If you're trying to have thread-specific bindings, then (after the problem you found will be fixed) the state will be separate too, so you'll not get any performance benefits from sharing the engine. So it seems to me that by having separate engine for every thread will solve your problem and will be more robust overall.
­čĹŹ 1
v
I understand, thank you