title: golang SQL DB opens connections when there are idle ones
body: <p>We are using <a href="https://github.com/dlmiddlecote/sqlstats" rel="nofollow noreferrer">https://github.com/dlmiddlecote/sqlstats</a> to expose the connection metrics, setting <code>maxOpenConns</code> to <code>300</code>, and <code>maxIdleConns</code> to <code>220</code>. The metrics graph is</p>
  <p><a href="https://i.stack.imgur.com/dDwUI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dDwUI.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/drC1r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/drC1r.png" alt="enter image description here" /></a></p>
  <p>We can see there are a lot of idle connections in the first graph. But the server is also closing connections due to max idle connections reached. I believe this means that the <code>sql.DB</code> package is creating more connections than <code>maxIdleConn</code>, and later has to remove them. But, looking at the first graph, why does <code>sql.DB</code> need to create more connections and exceed <code>maxIidleConn</code> if there are a lot of idle connections around already?</p>