Bug 569707 - [GTK] JVM terminates with SIGTRAP on display.post(SWT.KeyDown)
Summary: [GTK] JVM terminates with SIGTRAP on display.post(SWT.KeyDown)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.10   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 4.19 M1   Edit
Assignee: Alexandr Miloslavskiy CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2020-12-14 11:26 EST by Alexandr Miloslavskiy CLA
Modified: 2021-01-06 07:55 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandr Miloslavskiy CLA 2020-12-14 11:26:23 EST
Snippet sufficient to reproduce on Ubuntu 20.04:
--------
final Display display = Display.getDefault();
final Shell shell = new Shell(display);

final Event e = new Event();
e.keyCode = 'a';
e.character = (char)'a';
e.type = SWT.KeyDown;
e.widget = shell;
display.post(e);

while (!shell.isDisposed()) {
	if (!display.readAndDispatch())
		display.sleep();
}

display.dispose();
--------

When it happens, there are errors on console:
--------
(SWT:3222): Gdk-WARNING **: 17:20:18.309: losing last reference to undestroyed window
(SWT:3222): Gdk-ERROR **: 17:20:18.310: attempted to destroy root window
--------

And then JVM terminates. Sometimes it will also 100% CPU hang.
Comment 1 Andrey Loskutov CLA 2020-12-14 11:31:42 EST
Alexander, which Eclipse version is affected? Is this a recent regression?
Comment 2 Alexandr Miloslavskiy CLA 2020-12-14 11:33:47 EST
Investigating. I suspect Bug 518714, due to discussion in Bug 562774.
Comment 3 Alexandr Miloslavskiy CLA 2020-12-14 12:37:52 EST
When checking out SWT just before Bug 540809, snippet does not find any problems.
When checking out Bug 540809, there is the same problem as in SWT master.
Comment 4 Andrey Loskutov CLA 2020-12-14 13:56:35 EST
(In reply to Alexandr Miloslavskiy from comment #3)
> When checking out SWT just before Bug 540809, snippet does not find any
> problems.
> When checking out Bug 540809, there is the same problem as in SWT master.

Thanks. I assume you mean https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=e00275735f8b20c92b650305ad50ef8f845d6e64, which means, the problem starts with 4.10.

I can reproduce with this snippet on RHEL 7.4 / GTK 3.22 / Eclipse 4.15 too.

Alexandr, do you plan to provide a patch?

Here the full class to copy/paste:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;

public class Snippet {
    public static void main(String[] args) {
        final Display display = Display.getDefault();
        final Shell shell = new Shell(display);
        final Event e = new Event();
        e.keyCode = 'a';
        e.character = 'a';
        e.type = SWT.KeyDown;
        e.widget = shell;
        display.post(e);
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}
Comment 5 Andrey Loskutov CLA 2020-12-14 14:05:05 EST
Curious: Alexandr, how did you found this snippet? Is this reproducible somehow via "typical" IDE usage? If I see it right, the only reason it crashes is that we don't open the shell before posting the event? So how one can get such an event to not yet opened shell "in the wild"? Some automated (broken) test case?
Comment 6 Alexandr Miloslavskiy CLA 2020-12-14 14:07:20 EST
Yes, I'm working on a patch. It seems to be less scary than it initially seemed. I understand that problem only occurs when a focused window was not found.

I found it when trying to run SWT JUnit tests, namely 'Test_org_eclipse_swt_widgets_Text.test_backspaceAndDelete'. It does open a Shell, but it's not sufficient to prevent the problem, 'display.readAndDispatch()' also needs to spin enough.
Comment 7 Eclipse Genie CLA 2020-12-14 14:38:42 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173764
Comment 9 Alexandr Miloslavskiy CLA 2021-01-06 07:55:23 EST
Thanks for reviewing!