简体   繁体   中英

trying to connect to the mysql server on tomcat6: java.net.UnknownHostException

I having some trouble to connect to my mysql server from my java/scala worker.

Here is the stack trace I got:

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.GeneratedConstructorAccessor25.newInstance(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_27]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:355) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.6.0_27]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) ~[na:1.6.0_27]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at java.sql.DriverManager.getConnection(DriverManager.java:620) ~[na:1.6.0_27]
    at java.sql.DriverManager.getConnection(DriverManager.java:200) ~[na:1.6.0_27]
    at listen$IndexTransactionWorkerImpl.run(listen.scala:38) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at net.greghaines.jesque.worker.WorkerImpl.execute(WorkerImpl.java:630) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at net.greghaines.jesque.worker.WorkerImpl.process(WorkerImpl.java:600) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at net.greghaines.jesque.worker.WorkerImpl.poll(WorkerImpl.java:491) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at net.greghaines.jesque.worker.WorkerImpl.run(WorkerImpl.java:230) [indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at java.lang.Thread.run(Thread.java:679) [na:1.6.0_27]
Caused by: java.net.UnknownHostException: mysql-vip
    at java.net.InetAddress.getAllByName0(InetAddress.java:1229) ~[na:1.6.0_27]
    at java.net.InetAddress.getAllByName(InetAddress.java:1156) ~[na:1.6.0_27]
    at java.net.InetAddress.getAllByName(InetAddress.java:1092) ~[na:1.6.0_27]
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:249) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:305) ~[indexer-worker-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
    ... 29 common frames omitted

It works fine until a certain point, the worker is unable to resolve the host. If I restart the worker, it is working again.

Important thing: I am able to ping the host from the machine!

I tried to use ipv4 instead with Djava.net.preferIPv4Stack=true but I got the same error with the ipv4 stack.

I don't have any clue so far! Thanks for your help guys!

There can be multiple reasons for this Well it might happen if you do not manage your connection pool properly. in the sense if you are maintaining a connection pool yourself (or say using apache dhcp or something), then either you have too many connections open that everything gets blocked or not managing the resources well.

Another reason can be this: (It happened with us over a month back). When too many long queries were being executed at once. We did some optimizations on procedure side and things started working (By disabling read locks).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM