Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
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.
This is how a lot of people are implementing it: https://github.com/pjebs/go-skeleton/blob/master/app/providers/database.go#L61
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.
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 <firstname.lastname@example.org>