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 30487 - Deadlock during IDE start
Summary: Deadlock during IDE start
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: PC Linux
: P1 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords: RANDOM, THREAD
Depends on:
Blocks:
 
Reported: 2003-01-29 16:47 UTC by mslama
Modified: 2008-12-22 18:36 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump (12.21 KB, text/plain)
2003-01-29 16:48 UTC, mslama
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mslama 2003-01-29 16:47:11 UTC
I showed thread dump to David Strupl and he said
that synchronization  of
org.netbeans.core.NbURLStreamHandlerFactory.resultChanged()
when it calls allInstances() is dangerous. I saw
it on my fresh today dev build on JDK 1.4.1_01, Linux.
Comment 1 mslama 2003-01-29 16:48:06 UTC
Created attachment 8725 [details]
Thread dump
Comment 2 David Strupl 2003-01-29 16:55:09 UTC
I suggest just to remove the synchronized keyword from the mentioned
method. If two threads would try to call it simultaneously random one
would succeed. The same is without the synchronized. So - I don't
understand what does it do.
Comment 3 Tomas Pavek 2003-01-29 17:20:09 UTC
I cannot even start IDE on JDK 1.4.1 on W2K (tried dev builds 20030129
and 20030128). Comes up only for the first time (no user dir).
Comment 4 Jesse Glick 2003-01-29 17:23:14 UTC
Can't reproduce any problem myself, so I will just have to take your
(tpavek, mslama) word for it. Don't think I changed anything important
recently.

dstrupl: You cannot simply un-synchronize resultChanged, as it might
then set a new instance of handlers while some other thread is calling
createURLStreamHandler, causing array index out of bounds exceptions
etc. The synchronization protects access to this data.

However I can try moving allInstances() out of the synch block, and
synchronize only on actual accesses to the handlers instance field. I
don't think there is any particular reason to synch access to the
lookup result, since it will only be used when firing changes, which
is already synchronized by the lookup impl.

Note that the deeper causes of the deadlock are the usual suspects:

1. Cyclic dependencies in core infrastructure. The folder recognizer
is loading stuff from Services/ for FolderInstance, trying to find a
URL handler. Some of the layer files are using some protocol (nbres:
perhaps?) which is defined as a service in lookup. Therefore to look
for such a URL handler involves invoking URL handlers. In my
terminology from nbdev yesterday, the URL handlers should be split
into basic handlers (nbfs: and nbres: count) which are hardcoded (~
Stratum 0 I guess you could say) and may be used in Stratum 1, incl.
when defining new URL handlers; and secondary ones (e.g. nbdocs:)
needed only for Stratum 2 files (e.g. help sets).

2. Pointless multithreading. Main thread is doing some work, starting
up, then it suddenly blocks on folder recognizer for a while, then
(normally) continues. If everything were all in one thread, there
would be no deadlock here. (Nested calls might pose a problem for
other reasons, but at least they would not deadlock, and it would be
much more likely to be reproducible and easily testable/fixable.)
Comment 5 Jesse Glick 2003-01-29 17:50:23 UTC
committed     Up-To-Date  1.5        
core/src/org/netbeans/core/NbURLStreamHandlerFactory.java

Somebody please verify. I confirmed that *I* did not get deadlocks and
that unit tests pass. But I never saw the deadlock so I have no way of
knowing if I really fixed it.
Comment 6 Tomas Pavek 2003-01-30 09:55:10 UTC
Could not reproduce it in 20030130, looks ok.