Skip to content
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

driver.ErrBadConn when init packet read fails #736

Merged
merged 1 commit into from
Jan 25, 2018

Conversation

rdallman
Copy link
Contributor

@rdallman rdallman commented Jan 13, 2018

when initializing a connection, we can return drivers.ErrBadConn so that the
sql package can use this information to retry getting a connection. the sql
package will not give us this behavior unless we return that specific error.
pursuant to #302, this operation is another in the limited set of things that
seems safe to retry. we are trying to move to the post-302 world and ran into
this :)

I've run into this when using the new drivers.Conn() interface specifically,
though after digging into the sql package this seems like a similar path for
any query. After changing this return, I end up eventually getting a new conn
that is valid. It appears in my repro like the db was not yet ready, and would
just end up returning an invalid conn and giving up, the InvalidConn err came
from

return nil, ErrInvalidConn

which was the first read on the packet (an EOF). At least, returning a
drivers.ErrBadConn to let the db retry initializing the connection seems like
a safe operation.

thanks for maintaining this library :)

Description

Please explain the changes you made here.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

when initializing a connection, we can return drivers.ErrBadConn so that the
sql package can use this information to retry getting a connection. the sql
package will not give us this behavior unless we return that specific error.
pursuant to go-sql-driver#302, this operation is another in the limited set of things that
seems safe to retry. we are trying to move to the post-302 world and ran into
this :)

I've run into this when using the new drivers.Conn() interface specifically,
though after digging into the sql package this seems like a similar path for
any query. After changing this return, I end up eventually getting a new conn
that is valid. It appears in my repro like the db was not yet ready, and would
just end up returning an invalid conn and giving up, the InvalidConn err came
from https://github.com/go-sql-driver/mysql/blob/4a0c3d73d8579f9fc535cf5e654a651cbd57dd6e/packets.go#L38
which was the first read on the packet (an EOF). At least, returning a
drivers.ErrBadConn to let the db retry initializing the connection seems like
a safe operation.

thanks for maintaining this library :)
@rdallman
Copy link
Contributor Author

Created tests which fail without the change (if possible)

I have a 100% repro here: mattes/migrate#299 -- where before applying this (#736), running go test fails for the migrate library. that repro relies on the test suite behavior of starting up a mysql instance and waiting for it to be ready. the test suite in this repo appears to rely on a mysql instance already being available before running the tests. I'm happy to discuss options here, but it seems a pretty large divergence in testing methodology and I didn't want to get too far ahead without discussion [if necessary]. thanks again!

@arnehormann arnehormann merged commit bc14601 into go-sql-driver:master Jan 25, 2018
@rdallman rdallman deleted the badconn-init branch January 25, 2018 17:13
@rdallman
Copy link
Contributor Author

thank you!

bLamarche413 pushed a commit to bLamarche413/mysql that referenced this pull request Mar 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants