Recently, the filtering worker that I wrote in Java, kept getting connection errors. The worker uses JDBC to connect to MySQL server and do some queries. It kept throwing tons of look like this:

ERROR] Caused by: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

and also CommunicationsException errors from mysql adapter:

[ERROR] Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

At first I thought it was because there were too many threads that used up all the connections, so I switched to a different connection pool system called BoneCP. But these errors are still coming out from time to time.

Then I created a simple local cache Class as an middleman in between, to decrease the number of queries, but the errors still exist.

To make a long story short, after several more debugs and experiments, I started to realize that the problem might come from MySQL itself.

Then after some more tests, I finally got the answer. Turns out it was the bind-address setting, that caused the issue. After comment it in the mysql config file, everything starts to work smoothly, and the annoying errors are all gone.