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 267962 - 30s delay upon first connecting to a localhost database (due to URLClassLoader trying to DNS-resolve nbinst URL in URL.hashCode)
Summary: 30s delay upon first connecting to a localhost database (due to URLClassLoade...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Module System (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Tomas Hurka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-10 01:34 UTC by ebakke
Modified: 2016-12-03 03:03 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Stack trace showing the location of the 30 second delay (2.00 KB, text/plain)
2016-09-10 01:34 UTC, ebakke
Details
suggested patch against NbinstURLStreamHandler (2.40 KB, patch)
2016-09-11 08:58 UTC, matthias42
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ebakke 2016-09-10 01:34:23 UTC
Created attachment 161988 [details]
Stack trace showing the location of the 30 second delay

The first time (in a given NetBeans IDE session) that the user tries to connect to a database from the Services tab, there can be a 30 second delay under certain circumstances that depends on the user's network topology, even when the user is just trying to connect to localhost.

The delay comes from java.net.URL.hashCode trying to do DNS lookup on the hostname "org.netbeans.modules.db.drivers" during o.n.modules.db.explorer.DbDriverManager.getDriver's call to Class.forName. See the attached stack trace. The aforementioned hostname is clearly not meant for DNS lookup, but originates from the NetBeans-generated URL "nbinst://org.netbeans.modules.db.drivers/modules/ext/postgresql-9.2-1002.jdbc4.jar".

The underlying problem here is probably that java.security.CodeSource uses the horrible URL.hashCode for its own hash code, but maybe there is something that can be done on the NetBeans side to fix this...

Note that the 30 second delay only happens under certain network configurations, where the DNS request times out while trying to look up "org.netbeans.modules.db.drivers".
Comment 1 matthias42 2016-09-11 08:58:47 UTC
Created attachment 161995 [details]
suggested patch against NbinstURLStreamHandler

(In reply to ebakke from comment #0).
> The underlying problem here is probably that java.security.CodeSource uses
> the horrible URL.hashCode for its own hash code, but maybe there is
> something that can be done on the NetBeans side to fix this...

I aggree with this assessment. The implementation of hashCode and equals delegate to URLStreamHandler. The implementations are only appropriate if the URL schema is http-like.

This assumption breaks in case of the nbinst protocol. The nbinst protocol places the module as the host part. The attached patch fixes this by overriding the getHostAddress call to always return null (indicating that the hostname can't be resolved to an InetAddress). This switches the routines to use string comparison to determine hashCodes + equality.

The patch is covered by my OCA, if wished, I can push the patch in the 8.3/9.0 cycle (after the 8.2 release).
Comment 2 matthias42 2016-09-11 09:01:39 UTC
I'm reassigning this to platform/Module System as NbinstURLStreamHandler is defined in core.startup.base.
Comment 3 Tomas Hurka 2016-12-01 11:41:20 UTC
Thanks for the evaluation.

Fixed in profiler-main

changeset:   301753:d42e618f0bd1
user:        Tomas Hurka <thurka@netbeans.org>
date:        Thu Dec 01 12:36:39 2016 +0100
summary:     bugfix #267962, make sure NbinstURLStreamHandler does not use getHostAddress(); test added
Comment 4 Quality Engineering 2016-12-03 03:03:21 UTC
Integrated into 'main-silver', will be available in build *201612030001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/d42e618f0bd1
User: Tomas Hurka <thurka@netbeans.org>
Log: bugfix #267962, make sure NbinstURLStreamHandler does not use getHostAddress(); test added