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
database/sql: document what to do on DB.Ping error #23738
Comments
I'm not exactly sure what you mean by a "bad pool". How would you tell the difference between an incorrect DSN and a temporary network problem? I think retrying or closing the pool could both be correct. Glancing at the code you linked concerns me the author is confusing a DB pool with a single connection. I'm not convinced the docs need clarification, but I can look into it. Maybe we can discuss the pros and cons of each approch, maybe provide a recommendation. There is a direct tie here with how an application comes online (like needing a healthz endpoint or windows service). |
As an author of one Go SQL driver, author of one ORM-ish package, and contributor to numerous other SQL-related Go package, I can say that Sorry if it is not very specific. I will create separete specific issues and/or CL when I encounter those issues again. |
@AlekSi From what I can see, However, until go1.10 with the SessionResetter interface, there was no good way to expose normal database errors to users without poisoning the connection pool. Now the story is simple: return the normal custom or wrapped network database error to the user. Then when the ResetSession on the connection is called, return driver.ErrBadConn. I would love to have a conversation on another issue or https://groups.google.com/forum/#!forum/golang-sql about ways we can improve documentation in specific ways (or find an existing issue). One thing that would probably be helpful is to provide a bare-bones "real" database driver for others to inspect. |
Change https://golang.org/cl/101216 mentions this issue: |
Show two larger application examples. One example that could be used in a CLI, the other in a long running service. These demonstarates different strategies for handling DB.Ping errors in context. Fixes #23738 Change-Id: Id01213caf1f47917239a7506b01d30e37db74d31 Reviewed-on: https://go-review.googlesource.com/c/101216 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The documentation doesn't make clear what to do if we get an error "bad connection".
When Ping returns an error, is it advisable to close the DB object and create a new DB object to replace the old one?
After all, if Ping returns an error, something is clearly wrong.
Is it only the connection that is bad or the pool.
This is how a lot of people are implementing it: https://github.com/pjebs/go-skeleton/blob/master/app/providers/database.go#L61
The text was updated successfully, but these errors were encountered: