title: Connection timeouts with HikariCP
body: <p>I have a Spring Boot (v2.0.8) application which makes use of a HikariCP (v2.7.9) Pool (connecting to MariaDB) configured with:</p>
  
  <pre><code>minimumIdle: 1
  maximumPoolSize: 10
  leakDetectionThreshold: 30000
  </code></pre>
  
  <p>The issue is that our production component, once every few weeks, is repeatedly throwing <code>SQLTransientConnectionException " Connection is not available, request timed out after 30000ms..."</code>. The issue is that it never recovers from this and consistently throws the exception. A restart of the componnent is therefore required.</p>
  
  <p>From looking at the HikariPool source code, it would seem that this is happening because every time it is calling <code>connectionBag.borrow(timeout, MILLISECONDS)</code> the poolEntry is null and hence throws the timeout Exception. For it to be null, the connection pool must have no free entries i.e. all PoolEntry in the sharedList are marked <code>IN_USE</code>.</p>
  
  <p>I am not sure why the component would not recover from this since eventually I would expect a PoolEntry to be marked <code>NOT_IN_USE</code> and this would break the repeated Exceptions.</p>
  
  <p>Possible scenarios I can think of:</p>
  
  <ol>
  <li><p>All entries are <code>IN_USE</code> and the DB goes down temporarily. I would expect Exceptions to be thrown for the in-flight queries. Perhaps at this point the PoolEntry status is never reset and therefore is stuck at <code>IN_USE</code>. In this case I would have thought if an Exception is thrown the status is changed so that the connection can cleared from the pool. Can anyone confirm if this is the case?</p></li>
  <li><p>A flood of REST requests are made to the component which in turn require DB queries to be executed. This fills the connection pool and therefore subsequent requests timeout waiting for previous requests to complete. This makes sense however I would expect the component to recover once the requests complete, which it is not.</p></li>
  </ol>
  
  <p>Does anyone have an idea of what might be the issue here? I have tried configuring the various timeouts that are in the Hikari documentation but have had no luck diagnosing / resolving this issue. Any help would be appreciated.</p>
  
  <p>Thanks!</p>