title: Connection pooling with xorm and go-mysql
body: <p>Just cross-posting this from <a href="https://github.com/go-xorm/xorm/issues/422" rel="nofollow">github</a>.</p>
  
  <p>I am using xorm 0.4.3 with <a href="https://github.com/go-sql-driver/mysql" rel="nofollow">go-mysql</a>. We are on Golang 1.4.</p>
  
  <p>We have specified <code>maxIdleConnetions</code> and <code>maxOpenConnections</code> in <code>xorm</code> as below:-</p>
  
  <pre><code>var orm *xorm.Engine
  ...
  orm.SetMaxOpenConns(50)
  orm.SetMaxIdleConns(5)
  </code></pre>
  
  <p>And we are using the same single <code>xorm</code> instance to query Mysql.</p>
  
  <p>But still we are seeing lot of connections in <code>TCP Connection Establised</code> state which is way over the numbers I have configured in <code>maxIdleConnetions</code> and <code>maxOpenConnections</code>  state when we <code>lsof</code>:-</p>
  
  <pre><code>app 8747 10568 sandeshsharma 16u IPv4 691032 0t0 TCP 127.0.0.1:57337-&gt;127.0.0.1:mysql (ESTABLISHED)
  </code></pre>
  
  <p>We have also observed that even if we stop the MySQL, the connection numbers still remain fixed but in the <code>CLOSED_WAIT</code> state. If we shutdown the app then all connections go away.</p>
  
  <pre><code>app 8747 10844 sandeshsharma 38u IPv4 505058 0t0 TCP 127.0.0.1:54160-&gt;127.0.0.1:mysql (CLOSE_WAIT)
  </code></pre>
  
  <p>However in mysql process list it is showing the correct number of connections as I have specified in  <code>maxIdleConnetions</code> and <code>maxOpenConnections</code>.</p>
  
  <p>Can some one please explain me this behaviour? Why are we observing so much TCP connections even though we have specified <code>maxIdleConnetions</code> and <code>maxOpenConnections</code> to 5 &amp; 50 respectively?</p>