Skip to content

Commit

Permalink
[MSHADE-467] Improved concurrency problem fix
Browse files Browse the repository at this point in the history
Code review: Synchronising on session.getProjectBuildingRequest() is
less invasive than a global reentrant lock and therefore preferable to
the reviewer.

Co-authored-by: Romain Manni-Bucau <[email protected]>
  • Loading branch information
kriegaex and rmannibucau committed Jan 22, 2024
1 parent ae907a8 commit e7077c6
Showing 1 changed file with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -1050,8 +1048,6 @@ private void createDependencyReducedPom(Set<String> artifactsToRemove)
rewriteDependencyReducedPomIfWeHaveReduction(dependencies, modified, transitiveDeps, model);
}

private static final Lock LOCK = new ReentrantLock();

private void rewriteDependencyReducedPomIfWeHaveReduction(
List<Dependency> dependencies, boolean modified, List<Dependency> transitiveDeps, Model model)
throws IOException, ProjectBuildingException, DependencyGraphBuilderException {
Expand Down Expand Up @@ -1116,9 +1112,7 @@ private void rewriteDependencyReducedPomIfWeHaveReduction(
w.close();
}

// Lock critical section to fix MSHADE-467
try {
LOCK.lock();
synchronized (session.getProjectBuildingRequest()) { // Lock critical section to fix MSHADE-467
ProjectBuildingRequest projectBuildingRequest =
new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
projectBuildingRequest.setLocalRepository(session.getLocalRepository());
Expand All @@ -1128,8 +1122,6 @@ private void rewriteDependencyReducedPomIfWeHaveReduction(

getLog().debug("updateExcludesInDeps()");
modified = updateExcludesInDeps(result.getProject(), dependencies, transitiveDeps);
} finally {
LOCK.unlock();
}
}

Expand Down

0 comments on commit e7077c6

Please sign in to comment.