[
https://issues.apache.org/jira/browse/GROOVY-7407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17693680#comment-17693680
]
Jex Jexler edited comment on GROOVY-7407 at 2/26/23 5:28 PM:
-------------------------------------------------------------
FYI, I noticed a few days ago that the workaround as it stands here does not
work any more with Groovy 3 and 4, see the class
[{{DefaultGroovyCompiler.GrengineGrapeEngine}} in
Grengine|https://gitlab.com/jexler/grengine/-/blob/bf357c24278a15e28854b6db2c3ac9c8acd34b8c/src/main/java/ch/artecat/grengine/code/groovy/DefaultGroovyCompiler.java#L487]
where I implement it the new way, or you can use
{{Grengine.Grape.activate(...)}} with Grengine 3.0.2 or later to apply it
(independently of otherwise using Grengine for anything).
To me the proposed System Property {{groovy.grape.synchronize}} would still
make sense, maybe I would just implement it at some point in a fork (at leaste
for Groovy 4, I guess) and propose to eventually merge it (and maybe forget
about the option with indicating a class name for the lock, as the class would
be loaded via the GraveIvy class anyways, so maybe just a flag to synchronize
calls if the System Property exists at all would be good enough?)...
was (Author: jexler):
FYI, I noticed a few days ago that the workaround as it stands here does not
work any more with Groovy 3 and 4, see the class
[{{DefaultGroovyCompiler.GrengineGrapeEngine}} in
Grengine|https://gitlab.com/jexler/grengine/-/blob/bf357c24278a15e28854b6db2c3ac9c8acd34b8c/src/main/java/ch/artecat/grengine/code/groovy/DefaultGroovyCompiler.java#L487]
where I implement it, or you can use {{Grengine.Grape.activate(...) }}with
Grengine 3.0.2 or later to apply it (independently of otherwise using Grengine
for anything).
To me the proposed System Property {{groovy.grape.synchronize}} would still
make sense, maybe I would just implement it at some point in a fork (at leaste
for Groovy 4, I guess) and propose to eventually merge it (and maybe forget
about the option with indicating a class name for the lock, as the class would
be loaded via the GraveIvy class anyways, so maybe just a flag to synchronize
calls if the System Property exists at all would be good enough?)...
> Compilation not thread safe if Grape / Ivy is used in Groovy scripts
> --------------------------------------------------------------------
>
> Key: GROOVY-7407
> URL: https://issues.apache.org/jira/browse/GROOVY-7407
> Project: Groovy
> Issue Type: Bug
> Components: Compiler, Grape
> Affects Versions: 2.4.3
> Environment: Essentially independent of the environment, as long as
> Groovy scripts use Grape; also this bug seems to be present since at least
> Groovy 1.7.5.
> Reporter: Jex Jexler
> Priority: Minor
> Labels: Compile, Grape, Groovy, Ivy
> Attachments: GROOVY-7407-Jenkins-Pipeline.txt,
> GrabConcurrencyTest.java, GrapeAndGroovyShellConcurrencyTest.java,
> GroovyCompileConcurrencyTest.java,
> WorkaroundGroovy7407WrappingGrapeEngine.java,
> stacktrace-GrapeAndGroovyShellConcurrencyTest-1.txt,
> stacktrace-GrapeAndGroovyShellConcurrencyTest-2.txt,
> stacktrace-GroovyCompileConcurrencyTest-1.txt,
> stacktrace-GroovyCompileConcurrencyTest-2.txt
>
>
> If Groovy scripts that import the same libraries via Grape are compiled in
> separate threads, compilation may fail due to race conditions.
> This does not happen if several threads use the *same* instance of
> GroovyClassLoader (GCL), because parseClass() uses synchronization.
> But as soon as different GCLs are used in separate threads or if the compiler
> is used directly (CompilationUnit.compile()), the issue occurs and
> compilation can fail.
> Two Java unit tests have be attached, which reproduce the issue, although
> this cannot be guaranteed with 100% certainty, because there is a race
> condition.
> Two different stacktraces have been observed for each unit test (with origins
> in Grape and in Ivy), which have also been attached (plus in a different
> environment (Tomcat webapp CentOS) once a an exception down in Ivy had been
> observed that seemed to be related to unzipping a JAR file, but no precise
> record of that exists any more).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)