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 114552

Summary: Deadlock in ProjectManager
Product: projects Reporter: Martin Krauskopf <mkrauskopf>
Component: Generic InfrastructureAssignee: Milos Kleint <mkleint>
Status: RESOLVED FIXED    
Severity: blocker CC: anebuzelsky, issues, issues, mmirilovic
Priority: P1 Keywords: RANDOM, THREAD
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: deadlock.txt
deadlock.txt with read access
second patch

Description Martin Krauskopf 2007-09-03 19:24:27 UTC
See the attached thread dump. The "wizard-descriptor-asynchronous-jobs" waits - dir2Proj.wait(); while holding write
access to ProjectManager's mutex. But notification is not reached - nobody can reach the dir2Proj.notifyAll() since
ProjectManager's mutex is needed, but is held (in write access) by the waiting thread (??)
Not sure what role has "Versioning" thread which is also trying to gain ProjectManager's mutex. I supposed it's OK to
call VisibilityQuery from within ProjectManager's write access.... actually now I see there, in the ProjectManager, code:

  if (Thread.currentThread() == loadingThread) {
      throw new IllegalStateException("Attempt to call ProjectManager.findProject within the body of \
          ProjectFactory.loadProject (hint: try using ProjectManager.mutex().postWriteRequest(...) \
          within the body of your Project's constructor to prevent this)"); // NOI18N
  }

but it was not thrown...
Comment 1 Martin Krauskopf 2007-09-03 19:25:21 UTC
Created attachment 48000 [details]
deadlock.txt
Comment 2 Milos Kleint 2007-09-04 09:52:47 UTC
done. The problem was:
When Thread1 started loading projectA, it sets the loadingThread variable to Thread1.
Any thread attempting to load projectA now stops and waits for the load to finish.
However if Thread2 attempts to read projectB now, it resets loadingThread to Thread2 and if that happens before Thread1
gets into the wrong code that calls findProject(), the exception is not thrown and the Thread1 deadlocks.

Checking in ProjectManager.java;
/cvs/projects/projectapi/src/org/netbeans/api/project/ProjectManager.java,v  <--  ProjectManager.java
new revision: 1.34; previous revision: 1.33
Comment 3 Milos Kleint 2007-09-05 11:09:30 UTC
Checking in ProjectManager.java;
/cvs/projects/projectapi/src/org/netbeans/api/project/ProjectManager.java,v  <--  ProjectManager.java
new revision: 1.33.2.1; previous revision: 1.33
don
Comment 4 Martin Krauskopf 2007-09-06 08:42:20 UTC
Fresh trunk build from this morning (CET), hours or two old. Reproduced again. Again the similar problem without
exception. This time with read access only. Attaching thread dump. The fix was not sufficient, so reopening this one. I
can file a new one if you want.
Comment 5 Martin Krauskopf 2007-09-06 08:43:05 UTC
Created attachment 48231 [details]
deadlock.txt with read access
Comment 6 Milos Kleint 2007-09-06 13:33:34 UTC
Created attachment 48262 [details]
second patch
Comment 7 Milos Kleint 2007-09-06 13:40:50 UTC
The following scenario was not covered by previous fix:
ProjectA gets created, in createProject() calls findProject() on projectB and then findProject() on itself (projectA).

Now we keep a list of project folder FileObjects that are procesed by current thread. See patch.
Comment 8 Jesse Glick 2007-09-06 16:30:17 UTC
Again may be slightly clearer to @Override initialValue() -> new HashSet<FileObject>().
Comment 9 Petr Nejedly 2007-09-07 08:09:50 UTC
No, please.
You'd trade one/two conditions for a whole class, that's unnecessary waste.
Comment 10 Martin Krauskopf 2007-09-07 08:40:10 UTC
If it is dangerous to fixthis, I would vote for removing previously applied patch from the beta1 branch. The only
steps/trigger which reproduced/caused this so far was usage of VisibilityQuery in the Rails project. The VisibilityQuery
is not and will not be used in the beta1 branch. For now we have used workaround in Rails project. So maybe this could
be waived.
Comment 11 Milos Kleint 2007-09-07 09:05:37 UTC
Checking in ProjectManager.java;
/cvs/projects/projectapi/src/org/netbeans/api/project/ProjectManager.java,v  <--  ProjectManager.java
new revision: 1.33.2.2; previous revision: 1.33.2.1
done