Bug 528150

Summary: BuildManager may silently skip builds if running from different threads.
Product: [Eclipse Project] Platform Reporter: Mickael Istria <mistria>
Component: ResourcesAssignee: Mickael Istria <mistria>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: jamesblackburn+eclipse
Version: 4.7Keywords: performance
Target Milestone: 4.8 M5   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/112871
https://git.eclipse.org/c/platform/eclipse.platform.resources.git/commit/?id=f7869c09e53b6d72992696548806799550034d49
Whiteboard:
Bug Depends on:    
Bug Blocks: 527212    

Description Mickael Istria CLA 2017-12-05 07:35:57 EST
If one starts multiple project builds from different jobs/threads, then BuildManager can return an OK status whereas one of the build was actually skipped.

Here is a test to reproduce it:

	@Test
	public void testIndividualProjectBuildsInParallel() throws CoreException, OperationCanceledException, InterruptedException {
		JobGroup group = new JobGroup("Build Group", 5, getWorkspace().getRoot().getProjects().length);
		long duration = System.currentTimeMillis();
		for (IProject project : getWorkspace().getRoot().getProjects()) {
			Job job = new Job("Building " + project) {
				@Override
				public IStatus run(IProgressMonitor monitor) {
					try {
						project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
						return Status.OK_STATUS;
					} catch (CoreException e) {
						return new Status(IStatus.ERROR, "org.eclipse.core.tests.resources", e.getMessage(), e);
					}
				}
			};
			job.setJobGroup(group);
			job.schedule();
		}
		Assert.assertTrue("Timeout, most likely a deadlock", group.join(5000, getMonitor()));
		duration = System.currentTimeMillis() - duration;
		assertEquals(getWorkspace().getRoot().getProjects().length, TimerBuilder.getTotalBuilds());
	}

where all workspace projects have the TimerBuilder set, each of them counting a hit. Some are long running, some other immediate.
This test would typically fail to report that the TimerBuilder did run on all projects (only 3, 4 or 5 ones are actually run). This is a bug as per contract of project.build(...) which expects project to actually build or throw an exception, but not to silently skip the builder.

I went into details, and the very big culprit is the BuildManager.canRun(...) method which basically will skip any new build while one is running. This BuildManager and its methods have to be fixed to handle parallel builds (which are compatible with APIs/contracts and user expectations I believe).
Comment 1 Eclipse Genie CLA 2017-12-05 08:14:53 EST
New Gerrit change created: https://git.eclipse.org/r/112871
Comment 3 Mickael Istria CLA 2018-02-22 15:25:46 EST
*** Bug 307097 has been marked as a duplicate of this bug. ***