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: TestMaxOpenConns failing #7532
Labels
Milestone
Comments
I believe the problem is in database/sql.go, in here: func (db *DB) conn() (*driverConn, error) There's a sequence that runs roughly as follows. 1.) lock mutex, check db.numOpen and db.maxOpen to see if a new connection should be opened, unlock mutex 2.) do work to open a connection 3.) lock mutex, update db.numOpen, unlock mutex If two goroutines simultaneously get inside conn(), they may both decide to open a connection before either updates numOpen, allowing the number of open connections to exceed db.maxOpen. One solution could be to increment db.numOpen in step #1 and decrement it if the open fails; I've prepared a change that does this and the test case passes. Another would be to use db.pendingOpens as maybeOpenNewConnections and openNewConnection do. If you agree that this is the root cause and that the suggested fix is appropriate, please let me know and I'll submit a change for review. Thanks, -James |
I have a fix for this to be sent out shortly. Thanks for the repro & diagnosis! Owner changed to @bradfitz. Status changed to Started. |
CL https://golang.org/cl/95130043 mentions this issue. |
This issue was closed by revision ce6b75d. Status changed to Fixed. |
Issue #7798 has been merged into this issue. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: