jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
The Jsii Library is not thread safe. This has been confirmed several times using the CDK library in java. When attempting to build CDK templates in more than one thread, you are greeted with this error.
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)
The current workaround is to synchronize requests via a lock in Java when performing any actions with CDK.
Please update jsii to be thread safe.
Use Case
Attempting to build CloudFormation templates in more than one thread by leveraging CDK with Java.
Proposed Solution
There seems to be a static singleton of the JsiiEngine instance that is used to build constructs in CDK - regardless of what app is using it. Instead of JsiiEngine.getInstance() this could instead be new JsiiEngine(..) that could be used by an app object upon its creation.
Would investigate in updating all statically called methods that reference any jsii related objects to instead be standard object -> method calls instead.
Other Information
No response
Acknowledgements
[ ] I may be able to implement this feature request
Describe the feature
Hello,
The Jsii Library is not thread safe. This has been confirmed several times using the CDK library in java. When attempting to build CDK templates in more than one thread, you are greeted with this error.
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)
The current workaround is to synchronize requests via a lock in Java when performing any actions with CDK.
Please update jsii to be thread safe.
Use Case
Attempting to build CloudFormation templates in more than one thread by leveraging CDK with Java.
Proposed Solution
There seems to be a static singleton of the JsiiEngine instance that is used to build constructs in CDK - regardless of what app is using it. Instead of JsiiEngine.getInstance() this could instead be
new JsiiEngine(..)
that could be used by an app object upon its creation.Would investigate in updating all statically called methods that reference any jsii related objects to instead be standard object -> method calls instead.
Other Information
No response
Acknowledgements
CDK version used
v2.103.0
Environment details (OS name and version, etc.)
Mac OS Ventura