Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 560274 - Race condition when updating debug toolbar button states
Summary: Race condition when updating debug toolbar button states
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.12   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.15 RC1   Edit
Assignee: Simeon Andreev CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-18 07:40 EST by Simeon Andreev CLA
Modified: 2020-02-24 01:56 EST (History)
3 users (show)

See Also:
sarika.sinha: review+


Attachments
Video showing the problem, following the steps from the description. (1.26 MB, video/mp4)
2020-02-18 07:40 EST, Simeon Andreev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simeon Andreev CLA 2020-02-18 07:40:52 EST
Created attachment 281848 [details]
Video showing the problem, following the steps from the description.

To reproduce:

1. Debug Eclipse.
2. Debug a simple snippet with a breakpoint from the debuggee Eclipse:
public class Test {
    public static void main(String[] args) {
        System.out.println(); // set a breakpoint here
    }
}
3. Select the debug target in the Debug view ("Test at localhost:...), observe the suspend button in the main toolbar is enabled.
4. Select the suspended stack frame, observe the suspend button is disabled.
5. Set a breakpoint at "return false;" in "org.eclipse.debug.internal.core.commands.ForEachCommand.isExecutable(Object[], IProgressMonitor, IEnabledStateRequest)".
6. Select the debug target in the debuggee Eclipse again.
7. Select the suspended stack frame again.
8. Observe 2 breakpoint hits for the breakpoint from step 5.
9. Resume the breakpoint hit for the debug target, then resume the breakpoint hit for the stack frame.
10. Observe that the Debug view has selection on the debug target, but the suspend button is disabled (as if the stack frame was selected).

We observe this with Eclipse 4.12, I can reproduce this with latest Platform/JDT (see attached video "suspend_button_update_problem.mp4").
Comment 1 Simeon Andreev CLA 2020-02-18 08:30:30 EST
If I replace the result of org.eclipse.debug.core.commands.AbstractDebugCommand.getEnabledStateSchedulingRule(IDebugCommandRequest) with an exclusive rule, the problem is gone.

Looking at the Java doc of the method this is public API. We probably need to change the current behaviour in some way.
Comment 2 Paul Pazderski CLA 2020-02-18 08:42:41 EST
I'm not sure an exclusive rule is the perfect fix. Is the order in which the scheduled jobs are executed reliable?

Another solution might be to not spawn a job for each enablement update. Instead queue the requests, schedule one job and process all pending requests in correct order.
Comment 3 Eclipse Genie CLA 2020-02-18 08:49:15 EST
New Gerrit change created: https://git.eclipse.org/r/157900
Comment 4 Simeon Andreev CLA 2020-02-18 08:57:24 EST
(In reply to Paul Pazderski from comment #2)
> I'm not sure an exclusive rule is the perfect fix. Is the order in which the
> scheduled jobs are executed reliable?

It seems so.

> Another solution might be to not spawn a job for each enablement update.
> Instead queue the requests, schedule one job and process all pending
> requests in correct order.

Is this different to the rule? I think both kind of trample the initial concept of AbstractDebugCommand.getEnabledStateSchedulingRule().
Comment 5 Paul Pazderski CLA 2020-02-18 08:57:35 EST
Ah, with the change I understand what you meant with public API. I missed the scheduling rule methods in AbstractDebugCommand.
Comment 6 Paul Pazderski CLA 2020-02-18 08:59:41 EST
(In reply to Simeon Andreev from comment #4)
> Is this different to the rule? I think both kind of trample the initial
> concept of AbstractDebugCommand.getEnabledStateSchedulingRule().

It might be less overhead but if the job execution is ordered the scheduling rule is fine and (what I missed) already intended in this command framework.
Comment 7 Sarika Sinha CLA 2020-02-21 04:38:32 EST
I was not able to reproduce the problem exactly on Mac, but I do see a better scheduling rule after the change. 
I will be testing it on Windows to confirm.
Comment 8 Sarika Sinha CLA 2020-02-21 11:01:39 EST
(In reply to Simeon Andreev from comment #0)

> 9. Resume the breakpoint hit for the debug target, then resume the
> breakpoint hit for the stack frame.
> 10. Observe that the Debug view has selection on the debug target, but the suspend > button is disabled (as if the stack frame was selected).

On Windows and Mac, behaviour is little different. I have to disable all breakpoints and after resuming in the order, the selection remains on StackFrame and button disabled.

But If I don't disable the breakpoint, the breakpoints keep hitting for couple of times for different commands. After the patch this is more consistent.

@Andrey,
Did you get a chance to test it?
Comment 9 Sarika Sinha CLA 2020-02-24 01:54:09 EST
I don't see any disadvantage of putting this change. If the change helps on Linux, it is good to go.