Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365013

Summary: SwtBrowser causes JRE to crash
Product: [Eclipse Project] Platform Reporter: Yuhan Zhang <yzhang>
Component: SWTAssignee: Grant Gayed <grant_gayed>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: chrriis, remy.suen
Version: 3.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
the error log file from the crashed process. none

Description Yuhan Zhang CLA 2011-11-28 20:15:36 EST
Created attachment 207638 [details]
the error log file from the crashed process.

It happens in time that JRE crashes while a SwtBrowser is standing in a loop awaiting requests coming in through "Browser.setUrl(String)" and "Browser.evaluate(String)". This doesn't have happen with particular urls (when each problematic url is tested separately, they didn't appear), but it happens overtime when multiple requests on the same browser. It may also result in hanging as asyncExec not being responsive at executing the assigned Runnable.

(10 concurrent processes of the same app are loaded and executed in memory.)


The below is the taken-apart code to represent the situation:

- The SwtBrowser is initialized in one thread using:


Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.open();
Browser browser = new Browser(shell, SWT.MOZILLA);
Rectangle bound = new Rectangle(0,0,width,height);
shell.setBounds(bound);
browser.setBounds(bound);
Thread uiThread = Thread.currentThread();

while ( !shell.isDisposed() && !Thread.currentThread().isInterrupted()) {
	if (!display.readAndDispatch())
		display.sleep();
}


- The request for setting urls are coming in through asynExec from a seperate thread:

final String url = "http://www.example.com";
display.asyncExec( new Runnable() {
	public void run() {
		browser.setUrl( "about:blank" );    // erase previous content
		browser.setUrl(url);       // may hang or crash overtime
	}
} );


- The requests for evaluating javascript are coming in through the 3rd thread after 10 seconds of time-out :

Thread deplayedProcessingThread = new Thread() {
	@Override
	public void run() {
		try {
			int maxWait = 10*1000;
			LOGGER.info("wait browser to load for " + maxWait + " ms");
			Thread.sleep(maxWait);
			LOGGER.info("Wake up from for waiting for " + url);
		} catch (InterruptedException e) {
			LOGGER.info("deplayedProcessingThread interrupted, and omitted");
			return;
		}
		
		delayedProcessingThread = null;
		LOGGER.info("processing from the timeout thread. url=" + url);
		display.asyncExec( new Runnable() {
			public void run() {
				browser.stop();
				Object returnValue = browser.evaluate( MY_JAVASCRIPT_WITH_OBJECTS_RETURNED ));
				... // processing with the returnValue
			}
		});
	}
};
deplayedProcessingThread.start();



#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xb7e61b92, pid=18595, tid=2657889168
#
# JRE version: 6.0_22-b04
# Java VM: Java HotSpot(TM) Client VM (17.1-b03 mixed mode linux-x86 )
# Problematic frame:
# C  [libc.so.6+0x6fb92]
#
# An error report file with more information is saved as:
# /home/hadoop/hs_err_pid18595.log


Other fatal error may also occur (but only one log file has been attached):

Here are the error messages:
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x9cca4519, pid=10793, tid=2657803152
#
# JRE version: 6.0_22-b04
# Java VM: Java HotSpot(TM) Client VM (17.1-b03 mixed mode linux-x86 )
# Problematic frame:
# C  [libmozjs.so.1d+0xd519]  JS_SaveFrameChain+0x13
#
# An error report file with more information is saved as:
# /home/hadoop/hs_err_pid10793.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#



Another type of error message:
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0xb7f3da00, pid=16152, tid=2657725328
#
# JRE version: 6.0_22-b04
# Java VM: Java HotSpot(TM) Client VM (17.1-b03 mixed mode linux-x86 )
# Problematic frame:
# C  [libpthread.so.0+0x7a00]  pthread_mutex_lock+0x20
#
# An error report file with more information is saved as:
# /home/hadoop/hs_err_pid16152.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Comment 1 Grant Gayed CLA 2011-11-29 17:05:36 EST
The crash is happening in the event loop, so there is not an obvious hint there.  Your use of threads seems unnecessary given the Browser's asynchronous nature though.  Can you try each of the following changes in your app:

1. In your second provided code block (starts with "final String url =..."), change the asyncExec()'s Runnable to:

public void run() {
    browser.addProgressListener(new ProgressAdapter() {
        public void completed(ProgressEvent event) {
            browser.setUrl(url);       // may hang or crash overtime
            browser.removeProgressListener(this);
        };
    });
    browser.setUrl( "about:blank" );    // erase previous content
}

2. Change your third provided code block (starts with "Thread deplayedProcessingThread =...") to:

int maxWait = 10*1000;
display.timerExec(maxWait, new Runnable() {
    public void run() {
        // this runnable can be cancelled before its timer completes
        // by invoking "display.timerExec(-1, this)"
        browser.stop();
        Object returnValue = browser.evaluate(MY_JAVASCRIPT_WITH_OBJECTS_RETURNED ));
        //processing the returnValue...
    }
});

3. If these do not help, please try with the eclipse 3.7.1 release ( http://download.eclipse.org/eclipse/downloads/drops/R-3.7.1-201109091335/index.php ).  Also, it looks like you are using XULRunner 1.9.  It probably would not hurt to try to download a recent XULRunner release such as http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/3.6.24/runtimes/xulrunner-3.6.24.en-US.linux-i686.tar.bz2 , and point at it explicitly as described in the first two paragraphs of http://www.eclipse.org/swt/faq.php#specifyxulrunner .  It is possible that the newer XULRunner release may contain a fix for what you are seeing.
Comment 2 Yuhan Zhang CLA 2011-11-29 19:06:33 EST
It appeared the crashing only happenes with the older jar (org.eclipse.swt.gtk.linux.x86_3.6.2.v3659b.jar). The code starts to work without crashing after swt is upgraded to 3.7.1.