-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: if there is a panic during Stmt execution, we cannot release resources #50953
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
I know what's causing it and I'm dealing with it now |
take a look at this code from database/sql func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (Result, error) {
s.closemu.RLock()
defer s.closemu.RUnlock()
var res Result
strategy := cachedOrNewConn
for i := 0; i < maxBadConnRetries+1; i++ {
if i == maxBadConnRetries {
strategy = alwaysNewConn
}
dc, releaseConn, ds, err := s.connStmt(ctx, strategy)
if err != nil {
if err == driver.ErrBadConn {
continue
}
return nil, err
}
res, err = resultFromStatement(ctx, dc.ci, ds, args...) // PANIC HERE!
releaseConn(err) // NEVER EXECUTED
if err != driver.ErrBadConn {
return res, err
}
}
return nil, driver.ErrBadConn
} This can happen if we implement a Valuer interface where panic occurs |
Change https://golang.org/cl/382214 mentions this issue: |
Yes, Valuer must not panic:
To date I've not wanted to fix this. |
it's not just about |
This is the example I came across when I discovered this error There was no use of Valuer |
Fair enough. I've heard you. I'll see what we can do. |
I tried to reproduce in the test the call stack that leads to the error. To do this I had to implement a couple of driver interfaces. This shows that we are not protected against applications freezing if the driver that can panic when executing Exec or Query. When goroutine is frozen, we can't complete the test, so I added a 15-second timeout In any case, I corrected the tests today to make the problem I'm solving even clearer |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
This is the kind of algorithm that leads to a complete hang-up:
What did you expect to see?
I expect the pending functions to perform correctly and the goroutine to continue to panic
I do not expect the whole routine to hang up permanently
What did you see instead?
resources will not be fully released and closing the statement or transaction will cause the goroutine to hang
The text was updated successfully, but these errors were encountered: