diff --git a/connection.go b/connection.go index e4bb59e67..31ec5ead2 100644 --- a/connection.go +++ b/connection.go @@ -594,6 +594,7 @@ func (mc *mysqlConn) watchCancel(ctx context.Context) error { } // When ctx is already cancelled, don't watch it. if err := ctx.Err(); err != nil { + mc.cleanup() return err } // When ctx is not cancellable, don't watch it. diff --git a/connector.go b/connector.go index eac0f01aa..fd7e76924 100644 --- a/connector.go +++ b/connector.go @@ -60,7 +60,6 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) { // Call startWatcher for context support (From Go 1.8) mc.startWatcher() if err := mc.watchCancel(ctx); err != nil { - mc.cleanup() return nil, err } defer mc.finish()