Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.UnknownHostException: Test: Test: unknown error Failed to get local InetAddress for VMID

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>
like image 853
user3608352 Avatar asked Dec 06 '22 01:12

user3608352


2 Answers

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
like image 83
Jeremy S. Avatar answered Dec 31 '22 18:12

Jeremy S.


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.)

like image 22
Steve Waldman Avatar answered Dec 31 '22 18:12

Steve Waldman