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 20322 - Deadlock during turning on projects module
Summary: Deadlock during turning on projects module
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 3.x
Hardware: PC Linux
: P3 blocker (vote)
Assignee: David Strupl
URL:
Keywords: THREAD
: 20365 20594 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-02-08 09:56 UTC by Milan Kubec
Modified: 2008-12-22 18:57 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
full thread dump (20.23 KB, text/plain)
2002-02-08 09:57 UTC, Milan Kubec
Details
full thread dump (20.23 KB, text/plain)
2002-02-08 09:57 UTC, Milan Kubec
Details
Proposed patch for ErrorManager (3.87 KB, patch)
2002-02-11 17:04 UTC, David Strupl
Details | Diff
New patch - delegating error manager. (8.86 KB, patch)
2002-02-12 16:11 UTC, David Strupl
Details | Diff
Patch with synchronization fixed (9.61 KB, patch)
2002-02-13 16:09 UTC, David Strupl
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Milan Kubec 2002-02-08 09:56:08 UTC
I got deadlock during turning on projects module. Full thread dump is attached.
Comment 1 Milan Kubec 2002-02-08 09:57:12 UTC
Created attachment 4618 [details]
full thread dump
Comment 2 Milan Kubec 2002-02-08 09:57:14 UTC
Created attachment 4619 [details]
full thread dump
Comment 3 Milan Kubec 2002-02-08 10:48:02 UTC
Lowering priority to P3, since it's not reproducible.
Comment 4 Jesse Glick 2002-02-09 18:46:59 UTC
Probably ErrorManager.getDefault should not block on the folder
recognizer thread (i.e. lookup); it is called from too many different
places for this to be safe.
Comment 5 _ ttran 2002-02-11 08:55:56 UTC
David, DEADLOCK, so it's yours :-)
Comment 6 David Strupl 2002-02-11 15:09:00 UTC
Changing ErrorManager.getDeafult() ...
Comment 7 David Strupl 2002-02-11 15:51:01 UTC
*** Issue 20365 has been marked as a duplicate of this issue. ***
Comment 8 David Strupl 2002-02-11 17:04:41 UTC
Created attachment 4657 [details]
Proposed patch for ErrorManager
Comment 9 David Strupl 2002-02-11 17:17:58 UTC
Anyone willing to review my proposed patch? Thanks in advance - I need
at least one person to tell me that what I am doing is not completely
insane.

Please note that I propose to return simple() if two threads are
calling getDefault simultaneously. Also only the first thread calling
getDefault will call lookup. Not 100% deadlock proof but should help.
Another idea is to reschedule the initial lookup call to a thread that
would be known  (and meanwhile keep returning simple() before this
dedicated thread assigns a value to current).

Any suggestions how to do better?
Comment 10 Jesse Glick 2002-02-11 19:52:56 UTC
Patch looks OK to me. In principle it would be safest to not block on
lookup even on the first call, but in practice I doubt this matters.
ErrorManager.getDefault is called early, and NbTopManager.Lkp
initially hardcodes it to be NbErrorManager or
${org.openide.ErrorManager}, meaning lookup on it should not block on
anything important.
Comment 11 Jaroslav Tulach 2002-02-12 12:14:39 UTC
The patch is not perfect - somebody can get the simple()
implementation even errormanager is in lookup. I suggest to write a
delegating ErrorManager impl instead of the Simple one that will
obtain the list of EMs and delegate to them (also might solve SIM
module problem). If no found it will behave as our current simple().

The biggest problem will be with EM.getInstance (...) it needs to be
properly delegated and updated when list of EMs changes...
Comment 12 Jesse Glick 2002-02-12 12:52:11 UTC
In other words:

1. ErrorManager.getDefault() *always* returns a special delegating EM
inside ErrorManager.java. getInstance also creates a delegating EM.

2. Core continues to supply NbErrorManager in lookup and other modules
may add other ErrorManager impls in lookup.

3. ErrorManager asynchronously finds the set of ErrorManager impls in
lookup and listens to changes in it.

4. Any call to the delegating EM forwards the call to the first EM in
the current lookup result.

Still does not solve SIM's problem of needing to add some behavior to
the core NbEM without overriding all of it. That I think requires an
API addition - something like ErrorManager.{Event,Listener}.
Comment 13 David Strupl 2002-02-12 12:56:48 UTC
Yarda suggested:
Instead of your 4. use this one:

4. Any call to the delegating EM forwards the call to *all* EMs in
the current lookup result.

This should solve it, right?
Comment 14 Jesse Glick 2002-02-12 16:05:36 UTC
Maybe, but it seems questionable. What if there are several EM's
registered all of which implement notify() in a way which would
display something to the user? or log()? If it is NbErrorManager and
the SIM EM impl, I think notify() is OK, but it is not clear how well
this would work for e.g. NbErrorManager and TraceLogger.

The Java Event model seems to me better suited to this sort of thing:
you can use event.isConsumed() to decide whether to continue passing
along the event to another consumer.
Comment 15 David Strupl 2002-02-12 16:11:24 UTC
Created attachment 4664 [details]
New patch - delegating error manager.
Comment 16 David Strupl 2002-02-12 16:18:17 UTC
I have tried the delegating approach. I beleive we can go on with
delegating without listening. The interested module can always hide
the default implementation if they clash. I can imagine two kinds of
ErrorManagers - silent (logging) ones and those taking care of
everything (not needing the default one).

Anyone willing to check my sources? The delegating approach has to
deal with getInstance and updating the results. I will test it more
before integrating.
Comment 17 Jesse Glick 2002-02-12 16:41:42 UTC
I think that looks right, though findAnnotations should probably merge
results.
Comment 18 Jaroslav Tulach 2002-02-13 11:34:30 UTC
getInstance & setDelegates can collide due to no synchronization.
delegates do not keep original order.

otherwise ok - if we ignore the need of delegation for Annotation,
that is not needed right now, but can cause ClassCastEx. in future...






Comment 19 Jesse Glick 2002-02-13 14:35:41 UTC
What ClassCastException? It is a bug in an ErrorManager impl if it
assumes that it created all the attachments on a throwable. It should
check with instanceof if it requires info from a private impl class.
Comment 20 David Strupl 2002-02-13 14:42:50 UTC
Fixing the synchronization. Will post another patch soon.
As to order - allInstances returns a Collection. Should it be
SortedSet? Or JavaDoc for allInstances() improved?
Comment 21 David Strupl 2002-02-13 16:09:32 UTC
Created attachment 4691 [details]
Patch with synchronization fixed
Comment 22 Jesse Glick 2002-02-13 16:38:25 UTC
allInstances may return a Collection, but in typical usage the order
will be significant. In other cases it might not be. So I think
Collection is appropriate. SortedSet implies it is ordered by some
comparator, which is not the case. List implies that it is
*necessarily* ordered, which is also not the case.
Comment 23 David Strupl 2002-02-14 13:47:05 UTC
The patch applied in the main trunk.
ErrorManager 1.14.
Comment 24 phamernik 2002-02-18 09:29:01 UTC
*** Issue 20594 has been marked as a duplicate of this issue. ***
Comment 25 Milan Kubec 2002-10-17 10:49:31 UTC
Cannot reproduce.
Comment 26 Quality Engineering 2003-07-01 16:23:15 UTC
Resolved for 3.4.x or earlier, no new info since then -> closing.