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

[structurizr-site-generatr] Scripting context damaged when process workspaces in parallel #364

Closed
galuszkak opened this issue Dec 16, 2024 · 2 comments
Labels

Comments

@galuszkak
Copy link

galuszkak commented Dec 16, 2024

Expected

Scripts from different workspaces should have same results regardless if they are executed sequential or in parallel.

Actual

While working on PR for parallel branch building in structurizr-site-generatr there is issue that when building multiple workspaces in parallel Ruby scripting context is damaged and there is stack trace error:

javax.script.ScriptException: Error during evaluation of Ruby in /Users/kamil/Projects/Archive/structurizr-site-generatr/build/model-clone/2/docs/example/views.rb at line 9: (NoMethodError) undefined method `split' for ["tag1", "tag2", "tag3"]:Array
        at org.jruby.embed.jsr223.JRubyEngine.wrapRaiseException(JRubyEngine.java:277)
        at org.jruby.embed.jsr223.JRubyEngine.doEval(JRubyEngine.java:102)
        at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:126)
        at com.structurizr.dsl.ScriptDslContext.run(ScriptDslContext.java:70)
        at com.structurizr.dsl.ExternalScriptDslContext.end(ExternalScriptDslContext.java:23)
        at com.structurizr.dsl.StructurizrDslParser.endContext(StructurizrDslParser.java:1167)
        at com.structurizr.dsl.StructurizrDslParser.parse(StructurizrDslParser.java:242)
        at com.structurizr.dsl.StructurizrDslParser.parse(StructurizrDslParser.java:140)
        at nl.avisi.structurizr.site.generatr.CreateStructurizrWorkspaceKt.createStructurizrWorkspace(CreateStructurizrWorkspace.kt:10)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository$lambda$4(GenerateSiteCommand.kt:130)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository$lambda$5(GenerateSiteCommand.kt:117)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
        at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:667)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:765)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository(GenerateSiteCommand.kt:117)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.execute(GenerateSiteCommand.kt:77)
        at kotlinx.cli.ArgParser.parse(ArgParser.kt:657)
        at kotlinx.cli.ArgParser.parse(ArgParser.kt:530)
        at nl.avisi.structurizr.site.generatr.AppKt.main(App.kt:13)
Caused by: org.jruby.exceptions.NoMethodError: (NoMethodError) undefined method `split' for ["tag1", "tag2", "tag3"]:Array
        at RUBY.<main>(/Users/kamil/Projects/Archive/structurizr-site-generatr/build/model-clone/2/docs/example/views.rb:9)
Exception in thread "main" com.structurizr.dsl.StructurizrDslParserException: Error running script at views.rb, caused by javax.script.ScriptException: Error during evaluation of Ruby in /Users/kamil/Projects/Archive/structurizr-site-generatr/build/model-clone/2/docs/example/views.rb at line 9: (NoMethodError) undefined method `split' for ["tag1", "tag2", "tag3"]:Array at line 199 of /Users/kamil/Projects/Archive/structurizr-site-generatr/build/model-clone/2/docs/example/workspace.dsl: }
        at com.structurizr.dsl.StructurizrDslParser.parse(StructurizrDslParser.java:1065)
        at com.structurizr.dsl.StructurizrDslParser.parse(StructurizrDslParser.java:140)
        at nl.avisi.structurizr.site.generatr.CreateStructurizrWorkspaceKt.createStructurizrWorkspace(CreateStructurizrWorkspace.kt:10)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository$lambda$4(GenerateSiteCommand.kt:130)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository$lambda$5(GenerateSiteCommand.kt:117)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
        at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:667)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:765)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.generateSiteForModelInGitRepository(GenerateSiteCommand.kt:117)
        at nl.avisi.structurizr.site.generatr.GenerateSiteCommand.execute(GenerateSiteCommand.kt:77)
        at kotlinx.cli.ArgParser.parse(ArgParser.kt:657)
        at kotlinx.cli.ArgParser.parse(ArgParser.kt:530)
        at nl.avisi.structurizr.site.generatr.AppKt.main(App.kt:13)

Steps to reproduce

To reproduce that when using branch - https://github.com/FlyrInc/structurizr-site-generatr/tree/parallel-branch-building - just do (sometimes you need to re-run to get a crash - it's non deterministic):

$ ./gradlew run --args="generate-site -par -g https://github.com/FlyrInc/structurizr-site-generatr.git -b test1,test2,test3,test4,test5 -d test1 -w docs/example/workspace.dsl"

test1-5 branches are exactly the same. They contain simple script ( link: https://github.com/FlyrInc/structurizr-site-generatr/blob/test1/docs/example/views.rb ) that is exactly the same on couple of views:

tags = defined?(tags) ? tags : ""
def tags_filter(tags=[])
  puts "Tags: #{tags}"
end
tags_filter(tags=tags.split(","))

When running this without -par argument this works perfectly fine.

Version/build information

3.1.0 see: https://github.com/FlyrInc/structurizr-site-generatr/blob/ecd80c312d4625494ea78ee5df6345e16f802cb4/build.gradle.kts#L26

Severity

Minor

Priority

I'm willing to pay for this fix (add details below)

More information

No response

@galuszkak galuszkak added the bug label Dec 16, 2024
@simonbrowndotje
Copy link
Contributor

I likely won't have time to look into this properly before the end of the year, but the system property suggested here seems to resolve the issue, and should probably be added to the DSL parser code that builds the scripting engine.

@galuszkak
Copy link
Author

This links helps. When included System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe"); to my PR: avisi-cloud/structurizr-site-generatr#647

fixed this. Thanks for pointing me this to right direction!

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

2 participants