Skip to content

Commit

Permalink
Revert "Fix checking cancelled connections back into the connection p…
Browse files Browse the repository at this point in the history
…ool (go-sql-driver#1095)"

This reverts commit 6313f20.
  • Loading branch information
jsha committed May 20, 2021
1 parent 8e3eb81 commit 1cc8336
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Expand Up @@ -114,4 +114,3 @@ Multiplay Ltd.
Percona LLC
Pivotal Inc.
Stripe Inc.
Zendesk Inc.
4 changes: 0 additions & 4 deletions connection.go
Expand Up @@ -472,10 +472,6 @@ func (mc *mysqlConn) Ping(ctx context.Context) (err error) {

// BeginTx implements driver.ConnBeginTx interface
func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
if mc.closed.IsSet() {
return nil, driver.ErrBadConn
}

if err := mc.watchCancel(ctx); err != nil {
return nil, err
}
Expand Down
19 changes: 2 additions & 17 deletions driver_test.go
Expand Up @@ -2621,12 +2621,7 @@ func TestContextCancelBegin(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("CREATE TABLE test (v INTEGER)")
ctx, cancel := context.WithCancel(context.Background())
conn, err := dbt.db.Conn(ctx)
if err != nil {
dbt.Fatal(err)
}
defer conn.Close()
tx, err := conn.BeginTx(ctx, nil)
tx, err := dbt.db.BeginTx(ctx, nil)
if err != nil {
dbt.Fatal(err)
}
Expand Down Expand Up @@ -2656,17 +2651,7 @@ func TestContextCancelBegin(t *testing.T) {
dbt.Errorf("expected sql.ErrTxDone or context.Canceled, got %v", err)
}

// The connection is now in an inoperable state - so performing other
// operations should fail with ErrBadConn
// Important to exercise isolation level too - it runs SET TRANSACTION ISOLATION
// LEVEL XXX first, which needs to return ErrBadConn if the connection's context
// is cancelled
_, err = conn.BeginTx(context.Background(), &sql.TxOptions{Isolation: sql.LevelReadCommitted})
if err != driver.ErrBadConn {
dbt.Errorf("expected driver.ErrBadConn, got %v", err)
}

// cannot begin a transaction (on a different conn) with a canceled context
// Context is canceled, so cannot begin a transaction.
if _, err := dbt.db.BeginTx(ctx, nil); err != context.Canceled {
dbt.Errorf("expected context.Canceled, got %v", err)
}
Expand Down

0 comments on commit 1cc8336

Please sign in to comment.