Skip to content

Commit

Permalink
tidb-server: Fix issue 263
Browse files Browse the repository at this point in the history
Open tidb connect with dsn which contains unexists schema causes a
panic.
Fix issue pingcap#263
  • Loading branch information
shenli committed Sep 25, 2015
1 parent 5013e00 commit 60ade2f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tidb-server/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ func (cc *clientConn) Close() error {
delete(cc.server.clients, cc.connectionID)
cc.server.rwlock.Unlock()
cc.conn.Close()
return cc.ctx.Close()
if cc.ctx != nil {
return cc.ctx.Close()
}
return nil
}

func (cc *clientConn) writeInitialHandshake() error {
Expand Down
12 changes: 12 additions & 0 deletions tidb-server/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,15 @@ func runTestAuth(c *C) {
c.Assert(err, NotNil, Commentf("Wrong password should be failed"))
db.Close()
}

func runTestIssues(c *C) {
// For issue #263
unExistsSchemaDsn := "root@tcp(localhost:4001)/unexists_schema?strict=true"
db, err := sql.Open("mysql", unExistsSchemaDsn)
c.Assert(db, NotNil)
c.Assert(err, IsNil)
// Open may just validate its arguments without creating a connection to the database. To verify that the data source name is valid, call Ping.
err = db.Ping()
c.Assert(err, NotNil, Commentf("Connecting to an unexists schema should be error"))
db.Close()
}
4 changes: 4 additions & 0 deletions tidb-server/server/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ func (ts *TidbTestSuite) TestConcurrentUpdate(c *C) {
func (ts *TidbTestSuite) TestAuth(c *C) {
runTestAuth(c)
}

func (ts *TidbTestSuite) TestIssues(c *C) {
runTestIssues(c)
}

0 comments on commit 60ade2f

Please sign in to comment.