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 167218 - Race condition in the LibrariesStorage
Summary: Race condition in the LibrariesStorage
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Libraries (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-17 11:23 UTC by Petr Jiricka
Modified: 2009-08-05 06:18 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump (15.55 KB, text/plain)
2009-06-17 11:26 UTC, Petr Jiricka
Details
Patch (1.82 KB, patch)
2009-07-05 16:23 UTC, Tomas Zezula
Details | Diff
At the end the fix is not so ugly. Just trading a bit of correctness for deadlockfreeness. I was originally expecting something more horrible. Tomáši please comment. (7.81 KB, patch)
2009-07-22 15:42 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Jiricka 2009-06-17 11:23:22 UTC
Starting with a fresh install, opened a Java web application project. NetBeans froze as the "Opening Projects" dialog
was displayed. I am attaching a thread dump.
Comment 1 Petr Jiricka 2009-06-17 11:26:50 UTC
Created attachment 83687 [details]
Thread dump
Comment 2 Milos Kleint 2009-06-17 13:19:07 UTC
seems to be something with web project and libraries interaction, reassigning to web/project for evaluation. (other
alternative is java/platform I guess.)
Comment 3 David Konecny 2009-07-01 02:49:27 UTC
Tomas, this reminds me of issue 162575 and I would ask the same questions again "Perhaps
java.j2seplatform.libraries.J2SELibraryTypeProvider should just post update to a different thread (if there are really
some changes in property values)?"
Comment 4 Tomas Zezula 2009-07-03 17:34:53 UTC
I am already working on it. I will integrate it during weekend.
Comment 5 Tomas Zezula 2009-07-05 15:36:41 UTC
Not related to the issue #162575, but it's nearly the same as #166109 (deadlocks introduced by features on demand) where Jarda added waiting on 
FolderInstance. Removing the lock on the LibraryManager was easy by split of critical section, but this time the deadlock is caused by the project's mutex 
which was acquired by the WebProject before calling the LibraryManager (the libraries module cannot solve this, except of processing the events 
asynchronously (Folder Instance Processor thread) which is not a fix and it will introduce raceconditions). Anyway I still think that calling 
FolderInstance.waitFinished is not good idea.
Comment 6 Tomas Zezula 2009-07-05 16:19:47 UTC
The patch for async libs refresh, which I don't like as it's causes a raceconditition is here. The async call should be done only in the case of taskFinished.
Jardo, any other idea?
Comment 7 Tomas Zezula 2009-07-05 16:23:12 UTC
Created attachment 84382 [details]
Patch
Comment 8 Tomas Zezula 2009-07-05 16:25:47 UTC
The attached patch is not a "final" patch it's rather a sketch to show a possible solution if there is no nicer way. If we go this way I have to improve guarding of 
the shared state (LS.libraries).
Comment 9 Tomas Zezula 2009-07-15 18:16:15 UTC
Jardo, any progress on this?
Comment 10 Jaroslav Tulach 2009-07-22 15:22:50 UTC
I'll write a deadlock test and then I provide (a bit ugly) fix.
Comment 11 Jaroslav Tulach 2009-07-22 15:42:26 UTC
Created attachment 85075 [details]
At the end the fix is not so ugly. Just trading a bit of correctness for deadlockfreeness. I was originally expecting something more horrible. Tomáši please comment.
Comment 12 Jaroslav Tulach 2009-07-23 14:59:47 UTC
Tomáš is said to be on vacation this week, I'll be the next one. Let's do post integration review:
core-main#9e239b0332f2
The test is there and anyone can come up with better way to fix it later.
Comment 13 Quality Engineering 2009-07-24 17:41:45 UTC
Integrated into 'main-golden', will be available in build *200907241401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/9e239b0332f2
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #167218: Don't wait for correctly computed result while holding ProjectMutex
Comment 14 Tomas Zezula 2009-07-31 14:15:38 UTC
Yes, I was on the vacation.
The patch has two changes. 
1st) The LibraryManager doesn't cache Libraries when it's called under project mutex. This may negatively affect performance as the LibraryManager is used 
mostly under project mutex => the cache will not be used.

2nd) LibrariesStorage.initStorage waits on LibraryTypeRegistry only in the case when the code is not called under project mutex. As the initStorage may be 
called under the project mutex (LibraryManager.addLibrary, LibraryManager.createLibrary) it may case that some library definitions will not be stored as 
the LibraryTypeProvider is not yet loaded. But I don't fully understand the LibraryTypeRegistry.getDefault().waitFinished() in the LibrariesStorage.initStorage.

We should look at it again after vacations.
Comment 15 Tomas Zezula 2009-07-31 15:10:47 UTC
There is also problem that the waitFinished is called while holding the monitor on the LibrariesStorage

at org.openide.util.RequestProcessor$Task.waitFinished(RequestProcessor.java:791)
    [junit] 	at org.openide.loaders.FolderInstance.waitFinished(FolderInstance.java:347)
    [junit] 	at org.netbeans.modules.project.libraries.LibrariesStorage.initStorage(LibrariesStorage.java:218)
    [junit] 	- locked <0x1632fc90> (a org.netbeans.modules.project.libraries.LibrariesStorage)
    [junit] 	at org.netbeans.modules.project.libraries.LibrariesStorage.getLibraries(LibrariesStorage.java:319)
    [junit] 	- locked <0x1632fc90> (a org.netbeans.modules.project.libraries.LibrariesStorage)


Comment 16 Tomas Zezula 2009-08-04 12:18:52 UTC
Fixed in jet-main: 1399f036a1db
Comment 17 Quality Engineering 2009-08-05 06:18:21 UTC
Integrated into 'main-golden', will be available in build *200908050201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/1399f036a1db
User: Tomas Zezula <tzezula@netbeans.org>
Log: #167218:Race condition in the LibrariesStorage