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 41358 - Deadlock in InstanceDataObjectModule38420Test involving URLMapper
Summary: Deadlock in InstanceDataObjectModule38420Test involving URLMapper
Status: CLOSED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Filesystems (show other bugs)
Version: 4.x
Hardware: PC Linux
: P1 blocker (vote)
Assignee: David Konecny
URL:
Keywords: TEST, THREAD
Depends on:
Blocks:
 
Reported: 2004-03-25 15:32 UTC by Jesse Glick
Modified: 2008-12-22 16:45 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Thread dump (12.14 KB, text/plain)
2004-03-25 15:34 UTC, Jesse Glick
Details
Another deadlock encountered in a test (8.05 KB, text/plain)
2004-03-25 15:44 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2004-03-25 15:32:57 UTC
This is using the recent URLMapper lookup patch.
Perhaps needs to be even more radical, i.e. never
call L.R.allInstances() synch. Ugly.
Comment 1 Jesse Glick 2004-03-25 15:34:08 UTC
Created attachment 14152 [details]
Thread dump
Comment 2 Jesse Glick 2004-03-25 15:43:42 UTC
Hmm, looks like this may in fact happen more generally, during module
enablement change. Needs to be fixed somehow. Using static
synchronization on URLMapper is probably the real evil here -
allInstances may block on another thread (alas), which may in turn
need URLMapper. So you should have only "local" synchronization to
protect the integrity of the cache - i.e. do not hold any visible
locks while calling into Lookup.
Comment 3 Jesse Glick 2004-03-25 15:44:08 UTC
Created attachment 14154 [details]
Another deadlock encountered in a test
Comment 4 Jesse Glick 2004-03-25 15:46:01 UTC
Looks like all module/instance-related unit tests deadlock as a result
of this. Cannot run core tests.
Comment 5 David Konecny 2004-03-25 16:11:22 UTC
Hmmm, I did not try core tests before commit.
Comment 6 David Konecny 2004-03-29 16:16:29 UTC
I'm solving stupid problem how to dump threads on Windows for
deadlocked test which runs in separate process forked by xtest. I do
not have kill utility on Windows and Cygwin does not work either.

As for the fix I see two options. #1) revert my change so that Lookup
is initialized staticaly and cache only instances or #2) restrict
URLMapper registration to META-INF/services.

In second case the URLMapper would call only
Lookups.metaInfServices(...) and that should prevent these deadlocks.
However what ClassLoader I should pass to metaInfServices method,
without calling Lookup.lookup(ClassLoader)? And it is sort of
incompatible change.
Comment 7 Jesse Glick 2004-03-29 16:45:34 UTC
Suggest third option: never call L.R.allInstances from within the body
of getInstances. Initialize cache to be the empty list, update it only
from within resultChanged, and in the static initializer try to
initialize it asynch (ugh).

Or trickier but maybe more effective - call L.R.allInstances synch but
do not do so while holding the monitor on URLMapper.class. So
getInstances might look like e.g.

private static List/*<URLMapper>*/ cache = new ArrayList();
private static List getInstances() {
    boolean doinit;
    synchronized (cache) {
        doinit = result == null;
    }
    if (doinit) {
        // If really necessary, replan this block to RP:
        result = Lookup.getDefault().lookup(new
Lookup.Template(URLMapper.class));
        updateInstances();
        result.addLookupListener(new LookupListener() {
            public void resultChanged(LookupEvent ev) {
                updateInstances();
            }
        });
    }
    synchronized (cache) {
        return new ArrayList(cache);
    }
}
private static void updateInstances() {
    List resultInstances = result.allInstances();
    synchronized (cache) {
        cache.clear();
        cache.addAll(resultInstances);
    }
}
Comment 8 David Konecny 2004-03-30 10:11:05 UTC
Fixed in:
Checking in src/org/openide/filesystems/URLMapper.java
new revision: 1.27; previous revision: 1.26

Test is passing now.
Comment 9 Marian Mirilovic 2005-12-16 16:01:46 UTC
closing