概要
Spring Bootで、jpaを使ってmysqlに接続しているときに、10分(600秒)でコネクションが切断されてしまって、DBの接続エラーが発生する事態があったので対応方法をメモ。
application.yml
すみません、例がmariadbです。
spring:
datasource:
url: jdbc:mariadb://xxx.xxx.xxx.xxx:3306/testdb
username: testuser
password: testpassword
driverClassName: org.mariadb.jdbc.Driver
testOnBorrow: true
validationQuery: SELECT 1
validationQuery
だけでいけるかと思ったけど、testOnBorrow
の設定が必要でした。
参考
http://yyhayashi303.hatenablog.com/entry/20120911/1347322683
http://stackoverflow.com/questions/22684807/spring-boot-jpa-configuring-auto-reconnect
なぞ
mysqlのコネクションが10分(600秒)で切断されてしまう事象は謎。
8時間(28800秒)で設定されてそうなんだが。
mysql> show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 5 |
| deadlock_timeout_long | 50000000 |
| deadlock_timeout_short | 10000 |
| delayed_insert_timeout | 300 |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| thread_pool_idle_timeout | 60 |
| wait_timeout | 28800 |
+-----------------------------+----------+
14 rows in set (0.37 sec)