From 930cb41f825e691f6c2bd8aa7d9ee1afd94e67ab Mon Sep 17 00:00:00 2001 From: Andrea Di Cesare Date: Fri, 27 Sep 2024 18:29:01 +0200 Subject: [PATCH] :bug: Close polyglot Context objects --- .../java/org/restheart/polyglot/AbstractJSPlugin.java | 2 +- .../java/org/restheart/polyglot/JavaScriptService.java | 6 ++++-- .../polyglot/interceptors/AbstractJSInterceptor.java | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/polyglot/src/main/java/org/restheart/polyglot/AbstractJSPlugin.java b/polyglot/src/main/java/org/restheart/polyglot/AbstractJSPlugin.java index e192f7d4a..48cd499ce 100644 --- a/polyglot/src/main/java/org/restheart/polyglot/AbstractJSPlugin.java +++ b/polyglot/src/main/java/org/restheart/polyglot/AbstractJSPlugin.java @@ -155,7 +155,7 @@ public static void addBindings(Context ctx, /** * - * @return the Context associated with this thread. If not existing, it instanitates it. + * @return the Context */ protected Context ctx() { var ret = context(engine, contextOptions); diff --git a/polyglot/src/main/java/org/restheart/polyglot/JavaScriptService.java b/polyglot/src/main/java/org/restheart/polyglot/JavaScriptService.java index 93a861d31..3d661503c 100644 --- a/polyglot/src/main/java/org/restheart/polyglot/JavaScriptService.java +++ b/polyglot/src/main/java/org/restheart/polyglot/JavaScriptService.java @@ -180,12 +180,14 @@ export function handle(request, response) { */ @Override public void handle(StringRequest request, StringResponse response) { - ctx().eval(this.handleSource).executeVoid(request, response); + try (final var ctx = ctx()) { + ctx.eval(this.handleSource).executeVoid(request, response); + } } /** * - * @return the Context associated with this thread. If not existing, it instanitates it. + * @return the Context */ @Override protected Context ctx() { diff --git a/polyglot/src/main/java/org/restheart/polyglot/interceptors/AbstractJSInterceptor.java b/polyglot/src/main/java/org/restheart/polyglot/interceptors/AbstractJSInterceptor.java index 13b5616cf..43593dfa7 100644 --- a/polyglot/src/main/java/org/restheart/polyglot/interceptors/AbstractJSInterceptor.java +++ b/polyglot/src/main/java/org/restheart/polyglot/interceptors/AbstractJSInterceptor.java @@ -47,8 +47,11 @@ public class AbstractJSInterceptor, S extends Response> * @param pluginClass * @param description * @param interceptPoint + * @param handleSource * @param mclient - * @param modulesReplacements + * @param resolveSource + * @param contextOptions + * @param config */ public AbstractJSInterceptor(String name, String pluginClass, @@ -73,7 +76,9 @@ public AbstractJSInterceptor(String name, * @param response */ @Override public void handle(R request, S response) { - ctx().eval(this.handleSource).executeVoid(request, response); + try (final var ctx = ctx()) { + ctx.eval(this.handleSource).executeVoid(request, response); + } } @Override