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
[MNG-7285] [3.8.x] Replace ThreadLocal in MavenProject with locking in MojoExecutor to fix MNG-6843 #578
[MNG-7285] [3.8.x] Replace ThreadLocal in MavenProject with locking in MojoExecutor to fix MNG-6843 #578
Conversation
Let's do the revert in one commit, the new change in a separate one. |
Oh well, I first had it this that way but that will be two reverts. But ok, I can do that... |
4e078a7
to
e82b1fe
Compare
@rmannibucau Do you consider this as a better approach than thread local? What about Olivier's PR? |
@michael-o yes, the fact it handles concurrency=1 to fall back on the well known and used behavior is a clear important step and the lock solves the original issue I think - I don't see a broken case like that at least. The thread local was creating bugs in mojo, inherited or not (even if both didnt have the exact same) so better to not try it further IMHO. |
Oliver's PR doesn't help when thread pools are involved, btw. @gnodet I'd love to hear your take on this. |
@famod I will do asap. At first glance, I wonder if this is somewhat related to https://issues.apache.org/jira/browse/MNG-7156 and #476. The problem and locking strategy are different, but if the problem is the access to the |
Maybe you should consider adding #570 or similar test into this PR to validate this fix and also prevent from future regressions. |
I will take care of the merging when done. |
Sure! |
I've tried to reproduce the problem with the latest |
I confirm that #476 seems to fix MNG-6843 as well. I've built maven-3.8.x with that Overall, I would prefer #476 over this because it also prevents inconsistencies in other places. It's also more fine grained in that it seems to reduce the locking scope to the actual project being executed whereas with my approach, all mojo executions have to wait for an aggregating execution, no matter which project they are about to be executed for.
If a "regular" mojo execution wants to run for project A, but an aggregating mojo execution comes first, chances are that A is indeed locked and the other execution has to wait for that. So there will be a "delay" but there is no way around that, a lock is a lock. What I don't fully understand yet: When is |
Yes, obviously. What I meant was less delay, because of the finer grained lock.
The |
I was under the impression that forked lifecycles/goals and aggregating executions are two different things? |
@michael-o I see you did the reversions in #595. Shall I update this PR so that it can be included in 3.8.4 or do you want to go with #476 instead? |
Please update |
e82b1fe
to
c3553e2
Compare
Done, all tests are still passing, including the "parallel-testbed". |
I have tried #476 on the testbed repo, I still see failures, unfortunately. |
As mentioned here #570 (comment), this removes the
ThreadLocal
fromMavenProject
that was introduced in 3.8.2 and instead adds locking toMojoExecutor
to prevent MNG-6843.The major advantage is that there are no threading visibility issues anymore when passing around
MavenProject
s.The major downside is that
MavenProject
artifacts are not "protected" anymore from concurrent modifications, just as in 3.8.1 and before.Another downside is higher overall build runtime in case an aggregating goal takes some time to finish as it will block all other mojo executions until finished (in parallel build mode).
It does fix MNG-6843 which can be verified via https://github.com/famod/parallel-testbed/tree/compiler-fix
PS: The root cause can only be solved with a proper refeactoring like #475 but I don't think even that is enough.
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MNG-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
MNG-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.