I was making modifications to one of our components, and running all of the unit tests revealed that all database-dependant integration tests were failing:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago.<snip> (cut for brevity’s sake)at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.<snip> (cut for brevity’s sake)at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
Strange error message, but as it turns out the inner exception was far more revealing:
java.net.ConnectException: Connection refused: connect
As can be expected, the local MySQL server was up and running, and I was able to connect with the command line tool as well as with SQLYog, so it was obviously not a problem with MySQL or the local firewall. Next up I tried to telnet to the appropriate port (the easiest way I know to check port-level connectivity) without success:
I next tried to connect to the loopback IP (127.0.0.1), and experienced a major WTF moment when the connection succeeded. I use Windows Server 2008 and, as it turns out, it supports IPv6 out of the box. localhost has a slightly different meaning under IPv6 (it maps to ::1), and as I understand it traditional IPv4 traffic is tunneled over the looback IPv6 connection; I’m not yet familiar enough with IPv6 to draw any conclusions on why the above shouldn’t work, but the bottom line is there are several ways of resolving the problem:
For me, changing the hosts file was the quickest solution because it works and is easy to revert. I’ll have to keep a very careful eye on the behavior of my machine though.
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u