Bug 486083 - AutoBuild might run into an infinite loop under certain conditions
Summary: AutoBuild might run into an infinite loop under certain conditions
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.8.2   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-Resources-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2016-01-19 02:33 EST by Christian Dietrich CLA
Modified: 2022-03-22 00:55 EDT (History)
7 users (show)

See Also:


Attachments
Sample Generator that reproduces the problem with some likelyhood (1.24 KB, application/octet-stream)
2016-01-19 02:36 EST, Christian Dietrich CLA
no flags Details
Reproducing Non Xtext Builder (6.51 KB, application/zip)
2017-05-17 04:13 EDT, Christian Dietrich CLA
no flags Details
Sample Project (738 bytes, application/zip)
2017-05-17 04:13 EDT, Christian Dietrich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Dietrich CLA 2016-01-19 02:33:48 EST
The Xtext AutoBuild / Incremental Build might run into an infinite loop under following conditions:

(1) the Workspace Option "Refresh using native hooks or polling" is enabled in the Eclipse preferences
(2) This makes PollingMonitor/RefreshManager/RefreshJob calling a workspaceoperation IResource.refreshLocal if a "outofsync" resource is found.
(3) This will lead to a AutoBuildJob.interrupt() via org.eclipse.core.internal.events.BuildManager.interrupt()
(4) This will lead to the Running XtextBuilder beeing canceled (the monitor watches the interrupt as well in XtextBuild.shouldCancelBuild)
(5) Asume we have a Generator that generates lots of files on a incremental Build this will leed to (2) finding actual out of sync resources since IFile.setContents is not atomic (I will attach a small Generator that reproduces this)

(6) since the build gets never finished it will start all over again
Comment 1 Christian Dietrich CLA 2016-01-19 02:36:32 EST
Created attachment 259250 [details]
Sample Generator that reproduces the problem with some likelyhood
Comment 2 Christian Dietrich CLA 2016-01-19 02:37:59 EST
P.S:

please note: debugging the PollingMonitor/RefreshManager/Job is tricky since it reschedules it self according to the time needed the last time.

if you do not debug the monitor it runs every 8 seconds on my machine
Comment 3 Christian Dietrich CLA 2016-01-19 02:40:59 EST
As a workaround we subclassed XtextBuilder an switched of the AutoRefresh during the Xtext Build

    @Override
    protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
            throws CoreException {
        ScopedPreferenceStore resourcesPluginPrefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, ResourcesPlugin.PI_RESOURCES);
        boolean old = resourcesPluginPrefs.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH);
        resourcesPluginPrefs.setValue(ResourcesPlugin.PREF_AUTO_REFRESH, false);
        try{
            return super.build(kind, args, monitor);
        } finally {
            resourcesPluginPrefs.setValue(ResourcesPlugin.PREF_AUTO_REFRESH, old);
        }
    }
Comment 4 Richard Schubert CLA 2017-05-17 02:42:42 EDT
I and several colleges have this bug and find working with xtext quite unnerving because of it.

When will this get fixed?
Comment 5 Christian Dietrich CLA 2017-05-17 02:43:33 EDT
i dont have a clue and no help ....
so potentially never ....
Comment 6 Christian Dietrich CLA 2017-05-17 02:48:28 EDT
imho this should be fixed inside the eclipse filesystem,
the polling thingy ....
Comment 7 Andrey Loskutov CLA 2017-05-17 02:55:05 EDT
(In reply to Christian Dietrich from comment #6)
> imho this should be fixed inside the eclipse filesystem,
> the polling thingy ....

Which way there? Any proposal?
Comment 8 Christian Dietrich CLA 2017-05-17 02:56:21 EDT
i need someone that helps me understand the problem better
and maybe create an example that reproduces the problem
outside of xtext
so that i can hand over the bug to platform ...
Comment 9 Christian Dietrich CLA 2017-05-17 04:05:52 EDT
well i actually can reproduce this without xtext .....
Comment 10 Christian Dietrich CLA 2017-05-17 04:13:14 EDT
Created attachment 268389 [details]
Reproducing Non Xtext Builder
Comment 11 Christian Dietrich CLA 2017-05-17 04:13:38 EDT
Created attachment 268390 [details]
Sample Project
Comment 12 Christian Dietrich CLA 2017-05-17 04:14:26 EDT
@Andrey Loskutov do you think it makes sense to file a platform bug?
Comment 13 Christian Dietrich CLA 2017-05-17 04:15:26 EDT
another option would be to await all generation for one file
before interrupting the xtext build
but i am not sure if that would be a good idea
Comment 14 Andrey Loskutov CLA 2017-05-17 04:22:56 EDT
(In reply to Christian Dietrich from comment #12)
> @Andrey Loskutov do you think it makes sense to file a platform bug?

I haven't tried the example, but if the infinite build happens with that example too, please simply move this bug to platform resources.
Comment 15 Christian Dietrich CLA 2017-05-17 04:35:26 EDT
well the point is i am not sure if the 

forgetLastBuildState is legit or not
Comment 16 Andrey Loskutov CLA 2017-05-17 05:10:26 EDT
(In reply to Christian Dietrich from comment #15)
> well the point is i am not sure if the 
> 
> forgetLastBuildState is legit or not

So the question here is if the code pattern below is legit:

build(){
	...
	if (isInterrupted()) {
		forgetLastBuiltState();
	}
}

This looks like this is a problem of the (non-incremental) builder, but on the other side, BuildManager also triggers forgetLastBuiltState() in 
org.eclipse.core.internal.events.BuildManager.getSafeRunnable(...).new ISafeRunnable() {...}.handleException(Throwable).

Question: can you modify the example to get this build manager code path involved?

For me it looks like a platform bug. I just wonder how this could be addressed?
Comment 17 Christian Dietrich CLA 2017-05-17 05:38:58 EDT
well xtext maintains internally what was build and what was not
so it will rebuild the current resource and the onces not build yet.
Comment 18 Christian Dietrich CLA 2017-05-17 06:26:08 EDT
@andrey i dont get your point

protected void forgetLastBuiltState() {
oldState = null;
forgetStateRequested = true;
rememberStateRequested = false;		
}

this is what xtext/my builde calls.
the build manager then picks it up
Comment 19 Christian Dietrich CLA 2017-05-17 06:35:42 EDT
git it. changing the code to

		if (isInterrupted()) {
			throw new OperationCanceledException("i was Interrupted");
		}

does that.

behaviour stays the same
Comment 20 Andrey Loskutov CLA 2017-05-19 11:35:19 EDT
Moved to the platform, patch is welcome.
Comment 21 Richard Schubert CLA 2017-06-02 04:58:18 EDT
I get an endless loop after updating xtext project resources externally, even though I have "refresh on access" rather than "refresh using native hooks or polling". Do you think the reason for my bug could still be same as for the bug described here, or should I file a seperate bug?
Comment 22 Christian Dietrich CLA 2017-06-02 05:02:07 EDT
it can be this issue but others as well. (e.g. subclipse)

you should debug

-if autobuild is cancelled
-if xtext build is interruped by this cancelaction or another reason

org.eclipse.xtext.builder.impl.XtextBuilder.handleCanceled(Throwable)
org.eclipse.core.resources.IncrementalProjectBuilder.forgetLastBuiltState()
org.eclipse.core.internal.events.AutoBuildJob.setInterrupted(boolean)
Comment 23 Ed Willink CLA 2017-06-26 10:11:33 EDT
(In reply to Andrey Loskutov from comment #16)
> For me it looks like a platform bug. I just wonder how this could be
> addressed?

From my observations there seems to be a fundamental problem witrh the platform.

It should be possible for e.g.
a) GIT to declare a multi-project change starting
b) GIT to do multiple project changes without any auto-build happening for the multi-projects
c) GIT to declare the multi-project change complete after computing a rebuild all/incremental recommendation to the auto-builder
d) platform to start all/incremental build

IMHO so long as incremental builds start every time an individual project file changes, the performance of a GIT commit change is guaranteed to be SH*T.
Comment 24 Brian de Alwis CLA 2017-08-02 14:41:45 EDT
I've been hitting occasional test failures on Travis in tycho-surefire tests that involve auto-build that sound just like this problem [1].  This is with Java-based WTP projects: no XText involved.   One of my team members suspects that some occasional test failures involving WTP XML validation may be related: in this case, expected validation errors aren't being marked, implying that the validation is either interrupted or somehow ended prematurely.

We've noticed that this happens almost exclusively on Neon and Oxygen.  We rarely see problems on Mars.

Debugging this 'remotely' is a pain.  I need to figure out create a feature patch for org.eclipse.core.jobs to introduce some instrumentation.

[1] https://github.com/GoogleCloudPlatform/google-cloud-eclipse/pull/1529#issuecomment-287403084
[2] https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/2076
Comment 25 Christian Dietrich CLA 2017-08-02 15:36:39 EDT
There are other places that cancel the build as well e.g. https://bugs.eclipse.org/bugs/show_bug.cgi?id=519776
Comment 26 Brian de Alwis CLA 2017-08-23 15:58:37 EDT
I've been running my failing test case with Rastislav Wagner's patch for bug 478634 (https://git.eclipse.org/r/56954) and haven't had any failures.  Could others see if it helps with their test cases?
Comment 27 Eclipse Genie CLA 2020-07-17 16:07:28 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 28 Tamas Miklossy CLA 2021-02-18 07:03:27 EST
Any update on this topic?

I have also encountered this problem recently on a customer project. The problem still exists (occurs occasionally) with Eclipse 2020-12 and Xtext 2.24.
Comment 29 Christian Dietrich CLA 2021-02-26 05:26:29 EST
for subclipse please check https://github.com/subclipse/subclipse/issues/48