com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Software caused connection abort: recv failed
Your mySQL connections are timing out before your connection pool recognizes them. There are multiple ways to fix this:
- Increase the timeout value in mysql config file (my.ini)
- Reduce the idle time in your connection pool, so that it will discard the connection before mysql will close it
- Add a validate connection query in your pool config so that the pool tests each connection before it gives it to you, but this can slow down the system terribly.
How to fix java.net.SocketException: Software caused connection abort: recv failed
i fixed this probleme by increasing the timeout value in mysql config file = C:\Program Files (x86)\MySQL\MySQL Server 5.1\my.ini :
[mysqld] wait_timeout=2147483 interactive_timeout=2147483
and then i have restarted mysql service.
thank you @EJP
Spring Boot: Communications link failure after some hours of inactivity with Hibernate, JDBC and MySQL
I solved the problem as described here:
http://blog.netgloo.com/2015/07/09/spring-boot-communications-link-failure-with-mysql-and-hibernate/ , adding these configurations in the application.properties
file:
spring.datasource.tomcat.testWhileIdle = true
spring.datasource.tomcat.timeBetweenEvictionRunsMillis = 60000
spring.datasource.tomcat.validationQuery = SELECT 1
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
So, you have a
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
java.net.ConnectException: Connection refused
I'm quoting from this answer which also contains a step-by-step MySQL+JDBC tutorial:
If you get a
SQLException: Connection refused
orConnection timed out
or a MySQL specificCommunicationsException:
, then it means that the DB isn't reachable at all. This can have one or more of the following causes:
Communications link failure
- IP address or hostname in JDBC URL is wrong.
- Hostname in JDBC URL is not recognized by local DNS server.
- Port number is missing or wrong in JDBC URL.
- DB server is down.
- DB server doesn't accept TCP/IP connections.
- DB server has run out of connections.
- Something in between Java and DB is blocking connections, e.g. a firewall or proxy.
To solve the one or the other, follow the following advices:
- Verify and test them with
ping
.- Refresh DNS or use IP address in JDBC URL instead.
- Verify it based on
my.cnf
of MySQL DB.- Start the DB.
- Verify if mysqld is started without the
--skip-networking option
.- Restart the DB and fix your code accordingly that it closes connections in
finally
.- Disable firewall and/or configure firewall/proxy to allow/forward the port.
See also:
- How should I connect to JDBC database / datasource in a servlet based application?
- Is it safe to use a static java.sql.Connection instance in a multithreaded system?
Official reasons for Software caused connection abort: socket write error
This error can occur when the local network system aborts a
connection, such as when WinSock closes an established connection
after data retransmission fails (receiver never acknowledges data sent
on a datastream socket).
See this MSDN article. See also Some information about 'Software caused connection abort'.
Related Topics
How Does Bitshifting Work in Java
Is There a Sophisticated File System Monitor for Java Which Is Freeware or Open Source
Maximum Size of a Method in Java 7 and 8
Mockito: Mock Private Field Initialization
Java Type Generic as Argument for Gson
What Does Maven Update Project Do in Eclipse
How to Give System Property to My Test via Gradle and -D
JPA Query.Getresultlist() - Use in a Generic Way
How to Display Bar Value on Top of Bar Javafx
Java: Infinite Loop Using Scanner In.Hasnextint()
How to Convert a Java Object to Xml with Open Source APIs
Java Key Listener in Commandline
Drag and Drop Custom Object from Jlist into Jlabel