eclipse-rap / org.eclipse.rap

Eclipse RAP Runtime (Remote Application Platform)
https://www.eclipse.org/rap/
Eclipse Public License 1.0
17 stars 19 forks source link

Infinite loop in RAPDragTracker #144

Open SOlECtiT opened 1 year ago

SOlECtiT commented 1 year ago

Incident: In the processing of RAPDragTracker in LightweightSystem of org.eclipse.rap.draw2d/src/org/eclipse/draw2d/LightweightSystem.java, if Canvas is forcibly terminated, processing within RAPDragTracker will loop infinitely.

Cause: If Canvas is forcibly terminated and display.isDisposed becomes true, there is no timing to exit the while loop.

Code Snippet:

while (tracking && !cancelled) {
    if (display != null && !display.isDisposed()) {
        display.syncExec(new Runnable() {
            public void run() {
                if (canvas.isDisposed()) {
                    tracking = false;
                    cancelled = true;
                    return;
                }
                Event ev = new Event();
                //...
            }
        });
    } else {
        break;
    }
}

Thread Dump:

"Worker-6" #62 prio=5 os_prio=0 tid=0x00007f4dfc2a7800 nid=0x3d42 runnable [0x00007f4dcd14d000]
   java.lang.Thread.State: RUNNABLE
    at org.eclipse.draw2d.LightweightSystem$RAPDragTracker$1.run(LightweightSystem.java:500)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Proposed Solution: To avoid an infinite loop, the while loop should be exited if display.isDisposed becomes true. If display.isDisposed() becomes true, it is possible to avoid an endless loop by exiting the while loop.

if (display != null && !display.isDisposed()) {
 (omitted)
} else {
 break;
}