title: How to disconnect cleanly from MySQL in R?
body: <p>This function does not close connections properly (so I reach a max limit of 16, which is not good obviously):</p>
  
  <pre><code>query.test = function(query) {
    con = dbConnect(MySQL(), groups = 'test')
    output = tryCatch({
      dbGetQuery(con, query)
      }, warning = function(w) {
        print(w)
      }, error = function(e) {
        print(e)
      }, finally  = function() {
        dbDisconnect(con)
      })
    return(output)
  }
  </code></pre>
  
  <p>I thought that statements in the <code>finally</code> clause always get executed, so it's not clear to me why this code does not work.</p>