-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Already cancelled context should not break mysqlConn #862
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
Conversation
733f66d
to
14e5817
Compare
@shogo82148 Please look at this. |
Don't break the connection when cancelled context is passed. Fix go-sql-driver#858
3bc5897
to
ad1e76e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@methane @shogo82148 It's me again ;) --- a/vendor/github.com/go-sql-driver/mysql/connection.go
+++ b/vendor/github.com/go-sql-driver/mysql/connection.go
@@ -595,10 +595,6 @@ func (mc *mysqlConn) watchCancel(ctx context.Context) error {
mc.cleanup()
return nil
}
- // When ctx is already cancelled, don't watch it.
- if err := ctx.Err(); err != nil {
- return err
- }
// When ctx is not cancellable, don't watch it.
if ctx.Done() == nil {
return nil
@@ -610,7 +606,7 @@ func (mc *mysqlConn) watchCancel(ctx context.Context) error {
mc.watching = true
mc.watcher <- ctx
- return nil
+ return ctx.Err()
}
func (mc *mysqlConn) startWatcher() { Above works perfectly. Then however I found out another tiny issue, but maybe it is exactly that - completely different issue. When first Ping doesn't reach context timeout (so, correctly returns |
If you are using this code, it's expected behavior. On first Ping, On second Ping, |
Yes, I think you are right. I was using different code, also with connection pool and different timings. Ok, looks good, thank you very much again and sorry for misleading comment. |
Description
When already closed context is passed, context-aware APIs like
Ping()
should return error soon, and not close the connection.Fixes #858
Checklist