Worth Ubuntu 16.04 . Put TomCat 8 , flooded the site - it works. After almost 24 hours of operation, the site becomes unavailable. At the same time, the hosting machine itself works and tomcat itself on it too - checked with the sudo service tomcat status command. Why it happens? A reboot of the machine or tomcat itself helps. Tell me, what's the problem?

Thank.

  • one
    Did the application logs check? Perhaps, in the case of a database, all connections could be automatically closed if there were no calls to the database for a long time. - Victor Khovanskiy
  • @VictorKhovanskiy is what's in the logs: pastebin.com/HeJEH9GF . The thing is that if there is no connection with the database, then it is created, the project executes a connection to it. - Tsyklop
  • when this situation happens again, check the availability of your application server by checking open ports, for example telnet <server_name> <port_number> and let us know the result - Nikolay Baranenko
  • @Tsyklop in the logs is written directly, "No operations allowed after connection closed." And it is not automatically created. - Victor Khovanskiy

2 answers 2

You have written in the logs that MySQL connections are all closed. They are not re-created, but are suspended in the pool of connections, so an error occurs: "No operations allowed after connection closed.".

Add the following parameter autoReconnect=true to the database connection settings. For example, in this way:

 mysql://db_user:db_user@localhost/mydb?autoReconnect=true 
  • one
    autoReconnect=true - not a reliable solution. It is better to use a pool of connections with an automatic check of the connection before taking it from the pool and with periodic automatic updating (reconnection) of connections. - Roman
  • @Roman Is there any standard pool from the Spring Framework that provides this functionality? - Victor Khovanskiy
  • one
    In spring there are only test implementations, they will not work. My personal choice is HikariCP. - Roman

MySql has a default connection timeout of 8 hours (28800/60/60) according to the documentation . 8 hours after the last query to the database, the connection with it is broken. To prevent a connection wait_timeout you can increase the wait_timeout parameter in the database settings to a higher value than 8 hours.

  • By this, you only remove the inevitable. And not in all cases there is access to the database settings. - Roman
  • @Roman may be distant, but nevertheless the author of the question now knows why this error occurs, as he asked. The correct option is to use the connection pool, as you wrote, I agree with that. - MrFylypenko