jsii libraries are not thread-safe
:rocket: Feature Request
Affected Languages
- [ ]
TypeScriptorJavascript - [ ]
Python - [x]
Java - [ ] .NET (
C#,F#, ...)
General Information
- JSII Version: 0.14.2
- Platform:
What is the problem?
Exception in thread "Thread-1" software.amazon.jsii.JsiiException: Malformed object reference. Expecting $jsii.byref
at software.amazon.jsii.JsiiObjectRef.parse(JsiiObjectRef.java:52)
at software.amazon.jsii.JsiiClient.createObject(JsiiClient.java:91)
at software.amazon.jsii.JsiiEngine.createNewObject(JsiiEngine.java:458)
When trying to run jsiiengine createNewObject in a multithreaded env, it causes above exception.
Hey,
jsii does not (yet) support multi-threading.
Regards, Romain.
Is there a best practice to avoid running into multi-processing issues when working with JSII? We're trying to speed up rendering of all of our resources (using cdktf and cdk8s) by running multiple processes (for different envs, for example). Without locking, unexpected errors pop up (I can paste them here, but I worry they won't be very indicative).
This issue has not received any attention in 2 years. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
I'd still be happy to hear if there are plans on this front or not. Do close the issue if this is not something that's on your roadmap, of course, but it would be a huge usability boost if implemented.
Hi, any updates on this? Is making JSii thread safe on your roadmap?
FWIW, we're using a ThreadLocal lock object in our Python code whenever we call JSII (specifically cdktf, in our case) 🤷♂️ It's not a great solution, as obviously it negates some of the multi-processing/threading.