-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: Tx.Commit and Tx.Rollback do not remove bad connections from pool #11264
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
Comments
CC @bradfitz |
I have written a test and a fix for this in https://golang.org/cl/13912. Please review. This is my first CL for Go, so let me know if I have made any missteps. |
CL https://golang.org/cl/13912 mentions this issue. |
wow... can we get this in 1.5.1 fixed please..? |
It's been like this forever. I'm not sure what the rush is. |
@johto sorry, but I don't see how that is a good reason to leave such a basic, and destructive bug because it's been "like this forever". 1.5.2, sure, I can understand that and be patient, but having to wait 6 months for this class of bug to be fixed saddens and worries me. I hope we can strive for a higher standard. |
My point is that since it's been like this forever, I expect most drivers to have worked around the issue already. For new drivers it feels unreasonable to expect everyone to be on 1.5.1 or later, so even the authors of such projects will need to work around the issue. What this bug needs more than anything in my view is publicity, not rushed fixes. |
I contribute to both sqlx and upper/db, and this is the first time I've heard of this bug. |
I suspect that the most popular sql drivers have worked around this issue or are blissfully unaffected because github.com/lib/pq indirectly mentions the issue in a comment in it's github.com/go-sql-driver/mysql actively initiates a transaction and will likely catch the bad connection at that point. github.com/mattn/go-sqlite3 doesn't appear to ever return Meanwhile, github.com/alexbrainman/odbc just added the ability to handle bad connections recently. Prior to that commit a bad connection required the application to close its The work around at the driver level seems to be that the driver must store additional state in the connection to allow returning The work around at the application level is much worse. As mentioned above, the application must call Since this bug has been around for a long time it does not seem to fit the criteria that Russ recently laid out for inclusion in a point release. Perhaps the issue has been around for so long that drivers are essentially required to handle it on their own. In that case the fix for this issue would be documenting the required behavior in the Another possibility is that returning
But of course |
go version go1.4.2 windows/amd64
This issue was originally discovered while using github.com/alexbrainman/odbc, but it does not seem to be a problem specific to that driver. It is minimally reproducible with the below test program.
The program runs a query inside a transaction five times. The commit (or rollback) of the second attempt returns
driver.ErrBadConn
.I expect the bad connection to get removed from the pool and subsequent transactions to occur on a fresh connection.
Instead database/sql keeps the bad connection in the pool and subsequent transactions reuse the bad connection and also fail.
The text was updated successfully, but these errors were encountered: