We are getting problems with driver.ErrBadConn, but only if we use the 
prepared statements. It seems to me that this is because DB.QueryContext 
retries with a fresh connection and Stmt.QueryContext does not. I want to 
verify whether this is a bug or an expected behaviour, 

When DB.QueryContext receives driver.ErrBaddConn from the driver it will 
retry twice (maxBadConnRetries) using cached connection (cachedOrNewConn 
strategy). If this fails, it will retry once more using new connection 
(alwaysNewConn strategy). The code is here: 
https://golang.org/src/database/sql/sql.go?s=7997:9207#L1223

Stmt.QueryContext will also retry twice (again maxBadConnRetries) using the 
cached connection. If this fails, it will return driver.ErrBadConn, without 
retrying using the new connection. The code is 
here: https://golang.org/src/database/sql/sql.go?s=7997:9207#L1935 
s.connStmt uses cachedOrNewConn strategy.

I think this is a bug (but I will be happy to hear otherwise), introduced 
in this 
commit: 
https://github.com/golang/go/commit/c468f94672af25bc34975ba96309e20e972fa340

Before this commit, maxBadConnRetries was 10 and retries where alway done 
using old (cached) connections. Commit changed the logic, decreasing the 
number of retires and adding one more retry on fresh connection. While 
decrease was global (both *DB and*Stmt), retry-using-fresh-connection logic 
was applied only to *DB. 

So is it a bug (aka something I can report 
on https://github.com/golang/go/issues) or is it an expected behaviour?

Thanks,
Krzysztof Dryƛ

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to