title: Akka Streams Hikari Connection Pool for MySQL Streaming
body: <p>I am streaming data from mysql using Slick 3 and Akka Streams. </p>
  
  <p>This is how I build my source</p>
  
  <pre><code>import slick.jdbc.MySQLProfile.api._
  val enableJdbcStreaming: (java.sql.Statement) =&gt; Unit = {statement =&gt;
      if (statement.isWrapperFor(classOf[com.mysql.cj.jdbc.StatementImpl])) {
         statement.unwrap(classOf[com.mysql.cj.jdbc.StatementImpl]).enableStreamingResults()
      }
    }
  val query = Tables.Foo.filter(r =&gt; r.isActive === true)
       .map(r =&gt; r.id).result.withStatementParameters(statementInit = enableJdbcStreaming)
  Source.fromPublisher(db.stream(query))
  </code></pre>
  
  <p>My application runs for like 20 minutes and then shuts down with the following error</p>
  
  <pre><code>[error] Exception in thread "abhipool network timeout executor" java.lang.NullPointerException
  [info] 15:31:46 INFO  [HikariPool] - abhipool - Close initiated...
  [error]     at com.mysql.cj.mysqla.io.MysqlaProtocol.setSocketTimeout(MysqlaProtocol.java:1397)
  [error]     at com.mysql.cj.mysqla.MysqlaSession$1.run(MysqlaSession.java:401)
  [error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  [error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  [error]     at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>I have a feeling that because my query is running for a very long time there is some kind of timeout occurring which is initiating this shutdown.</p>
  
  <p>My connection </p>
  
  <pre><code>mysql {
    profile = "slick.jdbc.MySQLProfile$"
    dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
    properties {
      driver = "com.mysql.cj.jdbc.Driver"
      url  = "jdbc:mysql://foo:3306/bar?useLegacyDatetimeCode=false&amp;serverTimezone=America/Chicago"
      user = "foo"
      password = "bar"
    }
    connectionTimeout = 0
    idleTimeout = 0
    maxLifetime = 0
    maxConnections = 40
    minConnections = 10
    poolName = "abhipool"
    numThreads = 10
  }
  </code></pre>
  
  <p>Dependencies</p>
  
  <pre><code>"com.typesafe.slick" %% "slick" % "3.2.1",
  "com.typesafe.slick" %% "slick-hikaricp" % "3.2.1",
  "mysql" % "mysql-connector-java" % "6.0.6",
  </code></pre>
  
  <p>How can I configure my application database connections so that even if my streaming application streams data for several days... it keeps running.</p>
  
  <p>There is an extremely lengthy conversation about this same issue <a href="https://github.com/brettwooldridge/HikariCP/issues/236" rel="nofollow noreferrer">here</a> but it doesn't tell me how to really fix this issue. This issues makes it totally impossible to write long running streaming tasks which use Mysql as a source.</p>