Issue description
I used DB.Begin() to start a transaction and DB.Commit() or DB.Rollback() to end transaction, but I found some connections in the status of "SLEEP" for quite a long time (> 2 hours). And this is not expected. So do I miss something to make sure the connections are all to be freed?
Example code
mgr.statsConn, err = sql.Open("mysql", statsConnStr)
// ......
tx, err := mgr.statsConn.Begin()
if err != nil {
LogError(FAIL_CRITICAL, DB, "Begin transaction failed:%v", err)
return err
}
defer tx.Rollback()
// ...
// multiple Exec clauses just like:
rst, err = tx.Exec(sqlStr)
if err != nil {
LogInfo("Update xxx error. Sql:%s, Error:%v", sqlStr, err)
return err
}
// ...
if err := tx.Commit(); err != nil {
LogError(FAIL_CRITICAL, DB, "Commit error:%v", err)
return err
}
sql.Open() will be called only once of the entire lifetime of the process. and mgr.statsConn will be used everytime when opening a transaction I'm wondering the right position for the tx.Rollback(). If error happens, is it necessary to call tx.Rollback()? Will tx be non-nill then?
Configuration
Go version:1.7.5
Server version: MYSQL 5.5.37-enterprise-commercial-advanced-log