Skip to content

Commit 023a9a2

Browse files
committed
fix: reuse shared Engine from JSPlugin to prevent concurrent Engine corruption
#663
1 parent 38f38e6 commit 023a9a2

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

polyglot/src/main/java/org/restheart/polyglot/interceptors/JSInterceptorFactory.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import java.util.Optional;
2929

30+
import org.restheart.polyglot.JSPlugin;
3031
import org.restheart.polyglot.PolyglotClassloaderHelper;
3132
import org.restheart.polyglot.PolyglotThreadUtils;
3233
import org.graalvm.polyglot.Engine;
@@ -64,13 +65,10 @@ public class JSInterceptorFactory {
6465
public JSInterceptorFactory(Optional<MongoClient> mclient, Configuration config) {
6566
this.mclient = mclient;
6667
this.config = config;
67-
try {
68-
// Engine.create() dispatched to the dedicated platform thread.
69-
// See JSPlugin.<clinit> for the rationale.
70-
this.engine = PolyglotThreadUtils.onPlatformThread(PolyglotThreadUtils::createEngine);
71-
} catch (Exception e) {
72-
throw new IllegalStateException("Error creating polyglot Engine", e);
73-
}
68+
// Reuse the single shared Engine from JSPlugin rather than creating a
69+
// second one. Two concurrent Engines corrupt Truffle's internal
70+
// DefaultContextThreadLocal bookkeeping (see oracle/graal#7520).
71+
this.engine = JSPlugin.engine();
7472
}
7573

7674
public PluginRecord<Interceptor<?, ?>> create(Path pluginPath) throws IOException, InterruptedException {

0 commit comments

Comments
 (0)