This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 71450 - Dead lock in SwingBrowserImpl
Summary: Dead lock in SwingBrowserImpl
Status: VERIFIED WONTFIX
Alias: None
Product: platform
Classification: Unclassified
Component: Window System (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@platform
URL:
Keywords: T9Y
: 75772 96199 115293 (view as bug list)
Depends on:
Blocks: 115293
  Show dependency tree
 
Reported: 2006-01-16 15:48 UTC by Jiri Skrivanek
Modified: 2011-12-12 13:19 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump (16.37 KB, text/plain)
2006-01-16 15:50 UTC, Jiri Skrivanek
Details
yet another deadlock (9.48 KB, text/plain)
2006-10-02 13:53 UTC, _ rkubacki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Skrivanek 2006-01-16 15:48:22 UTC
From attached thread dump it seems to me there is a dead lock in
SwingBrowserImpl. I faced it in automated test but I am not able to reproduce it
manually. The test opens a JSP in browser and then tries to reload it.

Build 20060115-1811, JDK1.5.0_06, WindowsXP.
Comment 1 Jiri Skrivanek 2006-01-16 15:50:02 UTC
Created attachment 28407 [details]
Thread dump
Comment 2 David Simonek 2006-01-17 14:54:11 UTC
Unfortunately, I don't see any deadlock in given threads dump. Event queue
thread is waiting for swingbrowser thread, but swingbrowser thread in running,
trying to read url page through socket connection. Then there is second thread
which ends in the same native method of socket reading.

So IMHO this may signalize JDK problem, please jskrivanek could you try to run
tests on other JDKs available?

Also ccing deadlock experts in case I overlooked something.
Comment 3 _ rkubacki 2006-01-17 15:30:17 UTC
I guess the problem started with
http://core.netbeans.org/source/browse/openide/src/org/openide/awt/Attic/SwingBrowserImpl.java?r1=1.29&r2=1.30

This Tim's commit mostly obsoleted the hack with filtered stream that postponed
opening of stream OTOH brought the possibility that RP tries to get the stream
(to find encoding or content type) while holding the SwingBrowserImpl lock and
someone  presses reload that is synchronized too and it will block the AWT thread. 

This can be a problem if you are debugging web app using this "browser" and set
breakpoint in the page. You would need to resume the app to proceed further in
stream reading but AWT is blocked. 
Comment 4 Jiri Skrivanek 2006-01-17 15:35:46 UTC
Radim found scenario how to easily reproduce it:

- set Swing HTML browser as default in Options
- create web application project
- toggle breakpoint at first line in index.jsp
- start debugging
- when browser appears click reload button and it freezes with the same thread dump.
Comment 5 _ rkubacki 2006-01-17 15:49:48 UTC
workaround to scenario mentioned by Jirka is to kill debugged process (from
other place than the IDE)
Comment 6 _ rkubacki 2006-05-02 12:29:05 UTC
*** Issue 75772 has been marked as a duplicate of this issue. ***
Comment 7 Jan Chalupa 2006-05-02 12:48:40 UTC
P2 (at the least).
Comment 8 _ tboudreau 2006-05-02 20:26:15 UTC
Not to say don't fix this if possible, but how common a scenario is using the 
Swing browser for debugging?  The debugger could just check the value of the 
default browser from the system filesystem (no dependency needed), and if it 
sees the Swing browser, say "Sorry, debugging w/ the swing browser isn't 
supported."

Not saying it's the right choice, just an expedient option.  FWIW, the change 
there was to fix another AWT blockage, so any fix should try not to revert 
issue 41891.  Commit log message:

"#41891 - swing browser blocks AWT queue checking for proxy, etc. before it 
gets around to asynchronously loading the URL.  Read through the JEditorPane 
code for this and can't find any reason it should not be safe on a non EQ 
thread, and it solves the problem.

Also improved error reporting to not include exception class name, and no 
stack trace dialog if you type in a bad URL."
Comment 9 Jiri Skrivanek 2006-05-03 08:00:52 UTC
I don't agree with that "Sorry" option. We use Swing browser in automated tests
and such option would prevent us from using it. 
Comment 10 _ rkubacki 2006-05-03 08:49:27 UTC
1) If this is important let's increase priority/escalate JDK bug #4714674:
JEditorPane.setPage(url) blocks AWT thread when HTTP protocol is used.

2) Re possible regression when fixing - did you write a test?

3) Threading and locking - I've read related code in JDK and core/openide many
times too and agree that it should be safe to call setPage from non-EDT. That's
the idea of Tim's original fix. OTOH the synchronization that was introduced
means the same problem as in original bug on the second attemp to load a URL or
reload the document (SwingBrowserImpl's RP hold the lock while connect to
internet and setURL or event handlers in EDT are trying to get it too).
Comment 11 _ rkubacki 2006-10-02 13:53:05 UTC
Created attachment 34763 [details]
yet another deadlock
Comment 12 _ rkubacki 2006-10-02 13:56:59 UTC
While trying to reproduce issue #85917 I get another similar deadlock. 
- call setPage() (for example select some menu item that opens browser)
- before it gets shown write some URL into location and hit Enter

EDT waits for SwingBrowserImpl lock to call setPage() asynchronously and thread
holding this lock call SU.iaw to get the stream.
Comment 13 _ rkubacki 2006-10-02 18:06:40 UTC
Wrapping the test with 

        String oldPropValue =
System.getProperty("org.openide.awt.SwingBrowserImpl.do-not-block-awt");
        System.setProperty("org.openide.awt.SwingBrowserImpl.do-not-block-awt",
"true");

        System.setProperty("org.openide.awt.SwingBrowserImpl.do-not-block-awt",
(oldPropValue != null)? oldPropValue: "false");

should fix the first problem. The second one that I've reported today needs
different solution.

Jirka: can you confirm that it helps you to write tests (in fact this is what
our JPDA debugger does when it starts debugging)?
Comment 14 _ rkubacki 2006-10-03 13:13:41 UTC
Checking in test/unit/src/org/openide/awt/SwingBrowserTest.java;
/shared/data/ccvs/repository/openide/awt/test/unit/src/org/openide/awt/SwingBrowserTest.java,v
 <--  SwingBrowserTest.java
initial revision: 1.1
done
Checking in src/org/openide/awt/SwingBrowserImpl.java;
/shared/data/ccvs/repository/openide/awt/src/org/openide/awt/SwingBrowserImpl.java,v
 <--  SwingBrowserImpl.java
new revision: 1.5; previous revision: 1.4
done
Comment 15 Jiri Skrivanek 2006-10-03 14:57:07 UTC
I verified it in build 20061003-1233 with JDK1.5.0_09 and JDK1.6.0. It works but
I found another issue 86384 (browser reloads page 3 times).
Comment 16 mslama 2007-10-02 17:05:53 UTC
Unfortunately this fix causes race condition between SwingBrowserImpl and JEditorPane as SwingBrowser calls
doc.putProperty(Document.StreamDescriptionProperty, null); to force reload and then calls
swingBrowser.setPage(requestedURL); to set this property again in non AWT thread BUT JEditorPane accesses property
Document.StreamDescriptionProperty without checking if it is null in AWT thread. So moving some code in SwingBrowserImpl
to non AWT thread without possibility to synchronize with Swing in AWT thread is *NOT* solution. See issue #115293 for
NPE caused by this. Any idea how to fix this issue *WITHOUT* moving code in SwingBrowserImpl from AWT thread is welcome.
Comment 17 mslama 2007-10-31 11:55:58 UTC
Never ending story which cannot be fixed without fixing http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4714674
Comment 18 mslama 2007-10-31 11:56:20 UTC
*** Issue 115293 has been marked as a duplicate of this issue. ***
Comment 19 mslama 2007-10-31 11:58:12 UTC
*** Issue 96199 has been marked as a duplicate of this issue. ***
Comment 20 Lukas Hasik 2008-04-10 21:16:07 UTC
moving opened issues from TM <= 6.1 to TM=Dev
Comment 21 mslama 2008-09-03 08:09:15 UTC
According to JDK bug status fix was delivered in JDK 7 b27. I will check.
Comment 22 Stanislav Aubrecht 2010-09-14 12:51:58 UTC
closing - patches welcome