jsii icon indicating copy to clipboard operation
jsii copied to clipboard

jsii libraries are not thread-safe

Open ajnarang opened this issue 6 years ago • 6 comments

:rocket: Feature Request

Affected Languages

  • [ ] TypeScript or Javascript
  • [ ] 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.

ajnarang avatar Aug 07 '19 08:08 ajnarang

Hey,

jsii does not (yet) support multi-threading.

Regards, Romain.

RomainMuller avatar Aug 07 '19 18:08 RomainMuller

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).

mcouthon avatar Jun 13 '21 17:06 mcouthon

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.

github-actions[bot] avatar Jun 25 '23 06:06 github-actions[bot]

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.

mcouthon avatar Jun 29 '23 07:06 mcouthon

Hi, any updates on this? Is making JSii thread safe on your roadmap?

timtody avatar Oct 24 '23 07:10 timtody

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.

mcouthon avatar Oct 26 '23 10:10 mcouthon