gravitee-io / issues

Gravitee.io - API Platform - Issues
64 stars 26 forks source link

Groovy script compilation blocks the Vertx event loop #9653

Closed exalate-issue-sync[bot] closed 1 week ago

exalate-issue-sync[bot] commented 5 months ago

Description

description

description

When using the Groovy policy with a consequent script, the first call to the API takes a bit of time because of the Groovy script compilation. This compilation occurs on the Vertx event loop and is detected by the Vertx BlockThreadChecker:

io.vertx.core.impl.BlockedThreadChecker Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 6755 ms, time limit is 2000 ms","context":"default","exception":"io.vertx.core.VertxException: Thread blocked

at java.base@17.0.9/java.lang.Module.isOpen(Unknown Source)

at org.codehaus.groovy.vmplugin.v9.Java9.checkAccessible(Java9.java:378)

at org.codehaus.groovy.vmplugin.v9.Java9.checkCanSetAccessible(Java9.java:233)

at org.codehaus.groovy.reflection.ReflectionUtils.checkCanSetAccessible(ReflectionUtils.java:187)

at org.codehaus.groovy.reflection.CachedClass$3.lambda$initValue$1(CachedClass.java:89)

at org.codehaus.groovy.reflection.CachedClass$3$$Lambda$1283/0x00007fa0df804f78.test(Unknown Source)

at java.base@17.0.9/java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)

at java.base@17.0.9/java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)

at java.base@17.0.9/java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)

at java.base@17.0.9/java.util.stream.AbstractPipeline.copyInto(Unknown Source)

at java.base@17.0.9/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)

at java.base@17.0.9/java.util.stream.AbstractPipeline.evaluate(Unknown Source)

at java.base@17.0.9/java.util.stream.AbstractPipeline.evaluateToArrayNode(Unknown Source)

at java.base@17.0.9/java.util.stream.ReferencePipeline.toArray(Unknown Source)

at org.codehaus.groovy.reflection.CachedClass$3.lambda$initValue$4(CachedClass.java:91)

at org.codehaus.groovy.reflection.CachedClass$3$$Lambda$1281/0x00007fa0df804b00.run(Unknown Source)

at java.base@17.0.9/java.security.AccessController.executePrivileged(Unknown Source)

at java.base@17.0.9/java.security.AccessController.doPrivileged(Unknown Source)

at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:96)

at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:80)

…

at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:116)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:160)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)

at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)

at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)

at io.gravitee.policy.groovy.sandbox.SecuredInterceptor.onMethodCall(SecuredInterceptor.java:46)

at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)

at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)

at org.kohsuke.groovy.sandbox.impl.Checker$checkedCall$0.callStatic(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)

at 550c87bc817f0074dba2de60c4ccf3eb51dd1d02.run(550c87bc817f0074dba2de60c4ccf3eb51dd1d02:4)

at io.gravitee.policy.groovy.sandbox.SecuredGroovyShell.evaluate(SecuredGroovyShell.java:97)

at io.gravitee.policy.groovy.GroovyPolicy.runScript(GroovyPolicy.java:166)

at io.gravitee.policy.groovy.GroovyPolicy.onRequest(GroovyPolicy.java:83)

at io.gravitee.gateway.reactive.policy.PolicyChain.lambda$executePolicy$2(PolicyChain.java:103)

at io.gravitee.gateway.reactive.policy.PolicyChain$$Lambda$1325/0x00007fa0df7ce0b8.get(Unknown Source)

at io.gravitee.gateway.reactive.core.hook.HookHelper.hook(HookHelper.java:57)

at io.gravitee.gateway.reactive.policy.PolicyChain.executePolicy(PolicyChain.java:103)

at io.gravitee.gateway.reactive.policy.PolicyChain.lambda$execute$1(PolicyChain.java:95)

at io.gravitee.gateway.reactive.policy.PolicyChain$$Lambda$1323/0x00007fa0df7cda60.apply(Unknown Source)

at io.reactivex.rxjava3.internal.operators.mixed.FlowableConcatMapCompletable$ConcatMapCompletableObserver.drain(FlowableConcatMapCompletable.java:187)

…

To Reproduce

to-reproduce

to-reproduce

  1. On a Kubernetes environment, deploy an APIM Gateway with 500 milli CPU
  2. Create & deploy a V4 Proxy API with a Groovy policy
  3. Call the API with Postman
  4. See in the log the error.

Expected behavior

expected-behavior

expected-behavior

The compilation of the Groovy script should not block the Vertx event loop. Ideally, the first call should not compile the script which should be pre-compiled during the API deployment.

Current behavior

current-behavior

current-behavior

The compilation of the Groovy script occurs on the Vertx event loop which blocks the whole Gateway

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.