4

I am using c3p0 for connection pooling in my spring-jersey1.8 restful web service. While starting the application, I am getting the following error:

[com.mchange.v2.c3p0.impl.C3P0ImplUtils] INFO - Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness
java.net.UnknownHostException: Test: Test: unknown error
    at java.net.InetAddress.getLocalHost(InetAddress.java:1484)
    at com.mchange.v2.c3p0.impl.C3P0ImplUtils.generateVmId(C3P0ImplUtils.java:120)
    at com.mchange.v2.c3p0.impl.C3P0ImplUtils.<clinit>(C3P0ImplUtils.java:98)
    at com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<init>(PoolBackedDataSourceBase.java:227)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:62)
    at com.mchange.v2.c3p0.ComboPooledDataSource.<init>(ComboPooledDataSource.java:109)
    at com.mchange.v2.c3p0.ComboPooledDataSource.<init>(ComboPooledDataSource.java:105)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: Test: unknown error
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1479)
    ... 35 more

Does anyone have any idea what this error is about?

My spring-datasource.xml file has:

<!-- <context:property-placeholder location="/WEB-INF/spring.properties"></context:property-placeholder> -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"
    p:driverClass="com.mysql.jdbc.Driver"
    p:jdbcUrl="jdbc:mysql://localhost:3306/test2" 
    p:user="root" 
    p:password="root"
    p:acquireIncrement="5" 
    p:idleConnectionTestPeriod="60" 
    p:maxPoolSize="100"
    p:maxStatements="50" 
    p:minPoolSize="10" />

and pom.xml :

<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>
Brad Koch
  • 19,267
  • 19
  • 110
  • 137
user3608352
  • 397
  • 2
  • 5
  • 15

2 Answers2

9

As stated in another thread (linked in Steve Waldman's comments) the solution is to add the missing entry

java.net.UnknownHostException: Test: Test: unknown error

in this case it's Test in /etc/hosts

127.0.0.1    Test
Community
  • 1
  • 1
Jeremy S.
  • 6,423
  • 13
  • 48
  • 67
7

So, in a fit of overengineering intended to prevent collisions in the unlikely event many c3p0 DataSources are serialized into a distributed store, c3p0 tries to give each DataSource a globally unique "identityToken", which is accomplished in part by prefixing a "VMID", intended (perhaps unsurprisingly) to be a unique identifier for the current JVM.

The VMID partially determined by the internet address of the host on which it is running. So c3p0 calls java.net.InetAddress.getLocalHost() to find that. But calls to java.net.InetAddress.getLocalHost() can, unusually, fail, maybe because of security reasons, or some misconfiguration.

All of this is terrible, terrible overkill. Having written it, I am bashful, but I lost sleep over the very possibility that in theory identityTokens might conflict, violating an invariant that one identityToken should map to a unique pool. So, there it is.

So, we can't find the local address. Oops. We fall back to adding a bunch of randomness to the VMID we will generate for your running VM, to diminish the already infinitessimal likelihood of a conflict in practice. And then we move on. As the error message says, "This is unlikely to matter. At all."

If you want to make the error go away, you'll need to resolve the problem that causes calls to getLocalHost() fail in your environment. But you really can just ignore this.

(It looks like your environment is IPv6, which might have something to do with it. I should look into whether this code is appropriately robust to including IPv6 addresses in the VMID. But your code doesn't get far enough for that to matter.)

Steve Waldman
  • 13,689
  • 1
  • 35
  • 45
  • thanks i got the idea where is the issue but didn't got the solution – user3608352 Jul 07 '14 at 13:38
  • The solution is just to ignore the Exception. if you really hate it, you can set the logger called "com.mchange.v2.c3p0.impl.C3P0ImplUtils" to WARNING level, but I don't recommend that. c3p0 is intended to be logged at INFO. you'll see this Exception just once on startup, and it will otherwise do no harm. It would be good to understand why InetAddress.getLocalHost() fails in your environment. But I'm not sure how to debug that. – Steve Waldman Jul 07 '14 at 16:54
  • 3
    looking around a bit, see 1) an suggestion on stack overflow http://stackoverflow.com/questions/24612100/java-exception-in-thread-main-java-net-unknownhostexception-test-test-unkno and 2) a JDK7 bug, fixed as of a few days(!) ago: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7180557 maybe upgrading to the lated JDK is the way to go (if the latest released version contains the fix). – Steve Waldman Jul 07 '14 at 16:59
  • thanks @Steve that resolved my issue. i added entry in hosts file – user3608352 Jul 08 '14 at 05:20