Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompiling js script files fails from docker container #547

Closed
gkontos opened this issue Apr 10, 2024 · 6 comments
Closed

Precompiling js script files fails from docker container #547

gkontos opened this issue Apr 10, 2024 · 6 comments
Assignees
Labels

Comments

@gkontos
Copy link

gkontos commented Apr 10, 2024

When running the container 'outofcoffee/imposter-all:3.36.0' with a script, the following error is encountered:

20:06:34 DEBUG i.g.i.s.n.s.NashornScriptServiceImpl - Precompiling script: /opt/imposter/config/scripts/myscript.js
Exception in thread "DefaultDispatcher-worker-1" com.google.common.util.concurrent.ExecutionError: java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.FieldVisitor, but class was expected
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2053)
	at com.google.common.cache.LocalCache.get(LocalCache.java:3966)
	at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4863)
	at io.gatehill.imposter.scripting.nashorn.service.NashornScriptServiceImpl.getCompiledScript(NashornScriptServiceImpl.kt:171)
	at io.gatehill.imposter.scripting.nashorn.service.NashornScriptServiceImpl.initScript(NashornScriptServiceImpl.kt:105)
	at io.gatehill.imposter.scripting.common.service.DelegatingJsScriptServiceImpl.initScript(DelegatingJsScriptServiceImpl.kt:86)
	at io.gatehill.imposter.service.script.ScriptedResponseServiceImpl.initScriptFilesAndSteps(ScriptedResponseServiceImpl.kt:149)
	at io.gatehill.imposter.service.script.ScriptedResponseServiceImpl.initScripts(ScriptedResponseServiceImpl.kt:125)
	at io.gatehill.imposter.service.script.ScriptedResponseServiceImpl.afterRoutesConfigured(ScriptedResponseServiceImpl.kt:110)
	at io.gatehill.imposter.Imposter$configureRoutes$5.invoke(Imposter.kt:228)
	at io.gatehill.imposter.Imposter$configureRoutes$5.invoke(Imposter.kt:227)
	at io.gatehill.imposter.lifecycle.LifecycleHooks.forEach(LifecycleHooks.kt:77)
	at io.gatehill.imposter.Imposter.configureRoutes(Imposter.kt:227)
	at io.gatehill.imposter.Imposter.access$configureRoutes(Imposter.kt:88)
	at io.gatehill.imposter.Imposter$start$1.invokeSuspend(Imposter.kt:135)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@2c1cd0b0, Dispatchers.Default]
Caused by: java.lang.IncompatibleClassChangeError: Found interface org.objectweb.asm.FieldVisitor, but class was expected
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.field(ClassEmitter.java:606)
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.field(ClassEmitter.java:619)
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.defineCommonStatics(ClassEmitter.java:270)
	at org.openjdk.nashorn.internal.codegen.ClassEmitter.<init>(ClassEmitter.java:210)
	at org.openjdk.nashorn.internal.codegen.Compiler.createCompileUnit(Compiler.java:766)
	at org.openjdk.nashorn.internal.codegen.Compiler.createCompileUnit(Compiler.java:774)
	at org.openjdk.nashorn.internal.codegen.Compiler.addCompileUnit(Compiler.java:759)
	at org.openjdk.nashorn.internal.codegen.CompilationPhase$SplittingPhase.transform(CompilationPhase.java:117)
	at org.openjdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:614)
	at org.openjdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:641)
	at org.openjdk.nashorn.internal.runtime.Context.compile(Context.java:1531)
	at org.openjdk.nashorn.internal.runtime.Context.compileScript(Context.java:785)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine.asCompiledScript(NashornScriptEngine.java:486)
	at org.openjdk.nashorn.api.scripting.NashornScriptEngine.compile(NashornScriptEngine.java:178)
	at io.gatehill.imposter.scripting.nashorn.service.NashornScriptServiceImpl.getCompiledScript$lambda$3(NashornScriptServiceImpl.kt:180)
	at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4868)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3533)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2282)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2159)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049)
	... 20 more

The script in question was simplified to

var requestStore = stores.open('myRequest');

respond()
    .usingDefaultBehaviour()

This error does not occur when running the same version of imposter through the CLI or Jar files when running with openJDK 19 or jdk-22.

@rnestler
Copy link

I hit the same issue. It does work with the outofcoffee/imposter image, but https://docs.imposter.sh/scripting_modern_js/ recommended to use the gral-js plugin which I hoped would be included in the outofcoffee/imposter-all image.

@outofcoffee outofcoffee self-assigned this Apr 12, 2024
@gkontos
Copy link
Author

gkontos commented Apr 12, 2024

Ah! We didn't try the gral-js plugin, just the default js. We were using imposter-all for the faker plugin.

@outofcoffee
Copy link
Owner

outofcoffee commented Apr 12, 2024

Hi @gkontos and @rnestler - thank you for raising this and investigating.

This is caused by a clash between some of the plugins included in the all distro. Whilst we work on fixing that, there's an interim solution where the all distro now includes the js-graal plugin as suggested by @rnestler.

This is released in v3.36.1.

It looks like the work-around you used (specifying the IMPOSTER_JS_PLUGIN=js-graal environment variable) avoids this issue in v3.36.1.

@outofcoffee
Copy link
Owner

The underlying issue with the plugin conflict in the all distro should be fixed in v3.36.2.

Please let me know if this resolves the issue.

@outofcoffee outofcoffee assigned rnestler and gkontos and unassigned outofcoffee Apr 13, 2024
@rnestler
Copy link

v3.36.2 fixes the issue for me. I was wondering why graal-js isn't the default though. It was very surprising to me, that the JS scripting didn't support "modern" features by default.

@gkontos
Copy link
Author

gkontos commented Apr 16, 2024

The update resolves the issue for me too. Thanks!

@gkontos gkontos closed this as completed Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants