New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sqlite: implement driver.SessionResetter and driver.Validator #72
base: main
Are you sure you want to change the base?
Conversation
These implementations enable us to maintain connections in database/sql pools. Fixes #70
if c.stmts != nil { | ||
for _, s := range c.stmts { | ||
if err := s.resetAndClear(); err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this return ErrBadConn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the above case we could and probably should. In this particular case, that's unclear because:
ErrBadConn should be returned by a driver to signal to the sql package that a driver.Conn is in a bad state (such as the server having earlier closed the connection) and the sql package should retry on a new connection.
To prevent duplicate operations, ErrBadConn should NOT be returned if there's a possibility that the database server might have performed the operation. Even if the server sends back an error, you shouldn't return ErrBadConn.
Errors will be checked using errors.Is. An error may wrap ErrBadConn or implement the Is(error) bool method.
If we have potentially completed a tx we can not disambiguate between these conditions so we should not match BadConn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we generate the sort of error that gets database/sql to call ResetSession? if so, can you write a unit test that exercises this code?
} | ||
|
||
// ensure that all prepared statements are reset and unbound | ||
if c.stmts != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nil check is redundant because a range over a nil map does nothing
|
||
// ensure that all prepared statements are reset and unbound | ||
if c.stmts != nil { | ||
for _, s := range c.stmts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is almost right. in practice it would basically work. but the problem are statements created with persist=false
, which don't get put into c.stmts.
I can reverse it. It's absent from the docs. We do do have stats showing that we're not retaining cons. Either way yeah, I'll find a way to make some tests. |
These implementations enable us to maintain connections in database/sql pools.
Fixes #70