Here is a sample function that takes a connection to the database from the connection pool and does a query and processes the result returned.
func dbQuery() error {
con := db.getConn()
result, err := con.Query()
if err != nil {
return err
}
defer con.close() // or con.close()
// Processing the result takes a long time
return nil
}
Processing the result in this case takes a long time and close is not called for the connection, which means it is not returned to the connection pool.
Is it ok to directly call con.close() in cases like this when we know the resources are held for a long time even when they are not needed?