java H2 hanging on getLocalhost on arm32 device

2019-08-24 03:56发布

问题:

My application works fine on Windows, OSX an, Ubuntu and other flavours of linux until now.

On an arm 32 machine using jdk-8u121-linux-arm32-vfp-hflt.tar.gz it is hanging for five minutes on trying to create a Hibernate database using pure java database H2 and then giving up

public static void recreateDatabase()
    {
        Configuration config;
        config =
                HibernateUtil.getInitializedConfigurationAndRebuildAuditTables();
        new SchemaExport(config).create(false,true);
        factory = config.buildSessionFactory();
    }

I ran jstack during this period, of the relevent threads I think the key one is the 2nd one listed stuck at java.net.Inet4AddressImpl.lookupAllHostAddr but it just seem to be trying to get localhost , the machine is actually an embedded device and I wonder if that could mean it has weird networking that could be causing an issue ?

I have updated to the latest version of h2 (1.4.194), and the latest version of hibernate I could use without needing code changes (4.3.11.Final) due to changes they make to SchemaExport after that.

"main" #1 prio=5 os_prio=0 tid=0xb6105890 nid=0x7580 in Object.wait() [0xb6336000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x7c042900> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1414)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
        - locked <0x7c042900> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682)
        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
        at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:90)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
        at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
        at com.jthink.songlayer.hibernate.HibernateUtil.recreateDatabase(HibernateUtil.java:135)
        at com.jthink.songkong.cmdline.CmdCreateDatabase.start(CmdCreateDatabase.java:27)
        at com.jthink.songkong.cmdline.SongKong.cmdCheckDatabase(SongKong.java:1904)
        at com.jthink.songkong.cmdline.SongKong.cmdlineStart(SongKong.java:1574)
        at com.jthink.songkong.cmdline.SongKong.finish(SongKong.java:1699)
        at com.jthink.songkong.cmdline.SongKongForMelco.main(SongKongForMelco.java:33)

Running jstack during this 5 minute period I see:

"C3P0PooledConnectionPoolManager[identityToken->tys5dp9n86d1sl8vqh|f278eb]-HelperThread-#0" #9 daemon prio=5 os_prio=0 tid=0x7a1747b8 nid=0x75d3 runnable [0x79d60000]
       java.lang.Thread.State: RUNNABLE
            at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
            at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
            at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
            at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
            - locked <0x8eddfe38> (a java.lang.Object)
            at org.h2.util.NetUtils.getLocalAddress(NetUtils.java:272)
            - locked <0x7c040f80> (a java.lang.Class for org.h2.util.NetUtils)
            at org.h2.store.FileLock.lockSocket(FileLock.java:380)
            at org.h2.store.FileLock.lock(FileLock.java:138)
            - locked <0x7be62750> (a org.h2.store.FileLock)
            at org.h2.engine.Database.open(Database.java:662)
            - locked <0x7bc23a90> (a org.h2.engine.Database)
            at org.h2.engine.Database.openDatabase(Database.java:276)
            at org.h2.engine.Database.<init>(Database.java:270)
            at org.h2.engine.Engine.openSession(Engine.java:64)
            at org.h2.engine.Engine.openSession(Engine.java:176)
            - locked <0x8ee8bc50> (a org.h2.engine.Engine)
            at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
            at org.h2.engine.Engine.createSession(Engine.java:137)
            at org.h2.engine.Engine.createSession(Engine.java:27)
            at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
            at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
            at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
            at org.h2.Driver.connect(Driver.java:69)
            at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
            at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
            at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
            at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
            at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
            at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
            at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)

and then a number of threads with

"C3P0PooledConnectionPoolManager[identityToken->tys5dp9n86d1sl8vqh|f278eb]-HelperThread-#2" #11 daemon prio=5 os_prio=0 tid=0x7a312eb0 nid=0x75d5 waiting for monitor entry [0x79c]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at org.h2.engine.Engine.openSession(Engine.java:169)
        - waiting to lock <0x8ee8bc50> (a org.h2.engine.Engine)
        at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
        at org.h2.engine.Engine.createSession(Engine.java:137)
        at org.h2.engine.Engine.createSession(Engine.java:27)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
        at org.h2.Driver.connect(Driver.java:69)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
        at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)

Update with network info

more /etc/hosts

127.0.0.1       localhost

more /etc/resolv.conf

# Generated by dhcpcd for interface br0
nameserver 192.168.0.1

Update

Just been pointed out to me the issue is with H2 not **Hibernate, can this be amended to use a different method, it is H2 that is making the call in its NetUtils class

回答1:

I fixed in by adding this h2 property to my HibernateUtil configuration

System.setProperty("h2.bindAddress", InetAddress.getLoopbackAddress().getHostAddress());

I just hope it doesnt break any currenlty working installations !