Skip to content

Commit

Permalink
*: fix DB connection close and all_mode integration test (pingcap#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
csuzhangxc authored Dec 17, 2019
1 parent 41e9ecc commit 6612cf7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/conn/baseconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package conn

import (
"database/sql"
"database/sql/driver"
"fmt"
"strings"

Expand Down Expand Up @@ -207,5 +208,14 @@ func (conn *BaseConn) close() error {
if conn == nil || conn.DBConn == nil {
return nil
}
return terror.ErrDBUnExpect.Delegate(conn.DBConn.Close(), "close")

err := conn.DBConn.Raw(func(dc interface{}) error {
// return an `ErrBadConn` to ensure close the connection, but do not put it back to the pool.
// if we choose to use `Close`, it will always put the connection back to the pool.
return driver.ErrBadConn
})
if err != driver.ErrBadConn {
return terror.ErrDBUnExpect.Delegate(err, "close")
}
return nil
}
5 changes: 5 additions & 0 deletions tests/all_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -eu
cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $cur/../_utils/test_prepare
WORK_DIR=$TEST_DIR/$TEST_NAME
API_VERSION="v1alpha1"

function run() {
export GO_FAILPOINTS="github.com/pingcap/dm/dm/worker/TaskCheckInterval=return(\"500ms\")"
Expand Down Expand Up @@ -34,6 +35,10 @@ function run() {
run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml

# wait for task running
check_http_alive 127.0.0.1:$MASTER_PORT/apis/${API_VERSION}/status/test '"name":"test","stage":"Running"' 10
sleep 2 # still wait for subtask running on other dm-workers

# kill tidb
pkill -hup tidb-server 2>/dev/null || true
wait_process_exit tidb-server
Expand Down

0 comments on commit 6612cf7

Please sign in to comment.