天天看點

Connection marked as broken because of SQLSTATE(08S01), ErrorCode(0);Communications link failure

Question:

springboot 2.X多資料源配置,一段時間後連接配接無效,不能進行有效性驗證,提示:

Connection marked as broken because of SQLSTATE(08S01), ErrorCode(0);

Communications link failure

開始以為是HikariCP連接配接池配置的有問題,後面發現是程式的問題,使用EntityManager查詢操作,debug hikari也發現查詢後連接配接無法釋放

Solution:

使用@PersistenceContext?

  1. springboot data jpa中的entitymanager是transaction-scoped persistence contexts
  2. http://yukinami.github.io/2016/02/15/Spring%20Data%20JPA%20&%20EntityManager/
  3. https://stackoverflow.com/questions/10762974/should-jpa-entity-manager-be-closed
  4. validationTimeout,refer: https://github.com/brettwooldridge/HikariCP
    Connection marked as broken because of SQLSTATE(08S01), ErrorCode(0);Communications link failure