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 102217 - Deadlock when opening old project
Summary: Deadlock when opening old project
Status: VERIFIED FIXED
Alias: None
Product: javame
Classification: Unclassified
Component: Build System (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Adam Sotona
URL:
Keywords: THREAD
Depends on:
Blocks: 99509
  Show dependency tree
 
Reported: 2007-04-23 18:36 UTC by Lukas Hasik
Modified: 2007-08-13 14:25 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
thread dump (31.04 KB, text/plain)
2007-04-23 18:38 UTC, Lukas Hasik
Details
mobile project from 5.5 (22.24 KB, application/x-compressed)
2007-04-24 11:46 UTC, Lukas Hasik
Details
another thread dump (23.43 KB, text/plain)
2007-04-26 14:05 UTC, Lukas Hasik
Details
Diff of the suggested fixes (7.47 KB, patch)
2007-04-27 09:39 UTC, Adam Sotona
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Hasik 2007-04-23 18:36:54 UTC
070423

-open an older mobility project
-the "Opening Projects" dialog is there forever
-in status it show Collecting Project Dependencies

->thread dump attached
Comment 1 Lukas Hasik 2007-04-23 18:38:01 UTC
Created attachment 41491 [details]
thread dump
Comment 2 Lukas Hasik 2007-04-23 18:40:48 UTC
old == 5.5,  5.0
Comment 3 Adam Sotona 2007-04-24 10:45:20 UTC
The deadlock is caused by JsfJavaDataLoader using FileOwnerQuery to recognize
its primary file.

Increasing priority because this deadlock affects Mobility very frequently.
Comment 4 Lukas Hasik 2007-04-24 11:46:26 UTC
Created attachment 41537 [details]
mobile project from 5.5
Comment 5 Lukas Hasik 2007-04-24 11:48:18 UTC
this issue happens with "standard" NB distro when opening Mobility project. Test
project attached. This is stopper for M9
Comment 6 _ potingwu 2007-04-24 16:51:35 UTC
Visual web decided not to use FileOwnerQuery in JsfJavaDataLoader for NetBeans
5.5. I'm not sure why it comes back in NetBeans 6.
Comment 7 Quy Nguyen 2007-04-24 19:31:08 UTC
JsfJavaDataLoader only calls
org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils.getJspForJava,
which in turn uses FileOwnerQuery.  I think this should be fixed in the
visualweb/project/jsf module rather than in the dataloader.
Comment 8 _ potingwu 2007-04-24 23:04:14 UTC
I try the attached project but cannot reproduce it. Is it always reproducible?

From the stack, jsfloader was called by threads "Folder recognizer" and
"Versioning", and enter Mutex.readAccess. Theoretically the whole IDE should not
hang because Opening a project should all under Mutex.readAccess unless "opening
a old mobility project" involved Mutex.writeAccess. If so, then the coding in
'opening old' is not corrent in mobility modules.
Comment 9 _ potingwu 2007-04-24 23:06:26 UTC
BTW, I did see one hang with the status line says:
    Compiling D:\J2MEUnitTestingProject\src

I think that is not right when opening a project.
Comment 10 _ potingwu 2007-04-25 03:57:42 UTC
Now jsfloader validates the data object iff it's under a web project with visual
web framework used. This should fix the issue.
Comment 11 Lukas Hasik 2007-04-26 14:05:05 UTC
Created attachment 41729 [details]
another thread dump
Comment 12 Lukas Hasik 2007-04-26 14:14:03 UTC
reopening, it happened again in following configuration

NetBeans IDE Dev (Build 070426)
1.6.0-rc; Java HotSpot(TM) Client VM 1.6.0-rc-b104
Windows XP version 5.1 running on x86
en_US (nb); Cp1252
Comment 13 _ potingwu 2007-04-26 17:13:41 UTC
Look into the new thread dump, there is NO visualweb modules involved. Actually
it was not visualweb issue neither though visualweb now makes its codes not
participate this race-condition. (mobility pack's below action triggers the
incorrect dataloader actions.)

The issue is in the mobility pack. As I said before, I see "Compiling
D:\J2MEUnitTestingProject\src" when opening this project. Recently Java Sources
module did change some architecture and make various codes easier go into
deadlock if not carefully. Looks like mobility pack's codes are doing
writeAccess actions while 'opening project' should under readAccess.
Comment 14 Adam Sotona 2007-04-27 08:25:07 UTC
This is a different deadlock. The first one was caused by using FileOwnerQuery
from DataLoaders. 

This one is caused by direct propagation of project.properties change into all
listeners when project Mutex is locked in write mode.

I can fix this one in our CompiledSourceForBinaryQuery and J2MEProject.
Comment 15 Adam Sotona 2007-04-27 09:37:24 UTC
I've found a dangerous pattern when a synchronized query method requres reading
from project properties.

The sample here is CompiledSourceForBinaryQuery that is first invoked from
RepositoryUpdater but could not proceed because at the same time
AntProjectHelper already holds write Mutex to the project.
When the AntProjectHelper is ready with writing it fires property changes which
lead into subsequent call of CompiledSourceForBinaryQuery still under write Mutex.
So the deadlock is here - two instances of the query - one inside synchronized
block and one holding write Mutex.

I've found similar dengerous patterns also in  
FileBuiltQueryImpl, JavadocForBinaryQueryImpl and FileEncodingQueryImpl.

All the patterns are now fixed in trunk, waiting for approval to integrate into M9.
Comment 16 Adam Sotona 2007-04-27 09:39:38 UTC
Created attachment 41807 [details]
Diff of the suggested fixes
Comment 17 luky 2007-04-27 14:07:00 UTC
I see at least 2 thing which I don't like and it's not probably all
1) inconsistency in getRoots method of CompiledSourceForBinaryQuery and 
JavadocForBinaryQueryImpl
---
                FileObject[] fo = cache;
                if (fo == null) {
                    cache = new FileObject[0];
                    fo = createRoots();
---
                URL [] urls = cache;
                if (urls == null) {
                    urls = createRoots();

Why once is there  cache = new FileObject[0]; and in second case is missing 
cache=new URL[0] ?

2) Possible data integrity issue
   cache variable is changed in sychronized block, however URL [] urls = 
cache; or  FileObject[] fo = cache; are not synchronized
it should be something like sychronized(lock) { urls = cache };
Comment 18 Adam Sotona 2007-04-29 16:43:50 UTC
thanks for the comments
ad #1 - I found it in Compiled query and missed in Javadoc query   - thanks
ad #2 - it is safe even without synchronisation, the code excepts all possibilities


As there are no objections I am merging the chages into M9
Comment 19 Lukas Hasik 2007-08-13 14:25:10 UTC
v