File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -105,11 +105,16 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) {
105105}
106106
107107func (mc * mysqlConn ) Close () (err error ) {
108- mc .writeCommandPacket (comQuit )
108+ // Makes Close idempotent
109+ if mc .netConn != nil {
110+ mc .writeCommandPacket (comQuit )
111+ mc .netConn .Close ()
112+ mc .netConn = nil
113+ }
114+
109115 mc .cfg = nil
110116 mc .buf = nil
111- mc .netConn .Close ()
112- mc .netConn = nil
117+
113118 return
114119}
115120
Original file line number Diff line number Diff line change @@ -43,11 +43,15 @@ func (rows *mysqlRows) Close() (err error) {
4343
4444 // Remove unread packets from stream
4545 if ! rows .eof {
46- if rows .mc == nil {
46+ if rows .mc == nil || rows . mc . netConn == nil {
4747 return errors .New ("Invalid Connection" )
4848 }
4949
5050 err = rows .mc .readUntilEOF ()
51+
52+ // explicitly set because readUntilEOF might return early in case of an
53+ // error
54+ rows .eof = true
5155 }
5256
5357 return
@@ -58,7 +62,7 @@ func (rows *mysqlRows) Next(dest []driver.Value) error {
5862 return io .EOF
5963 }
6064
61- if rows .mc == nil {
65+ if rows .mc == nil || rows . mc . netConn == nil {
6266 return errors .New ("Invalid Connection" )
6367 }
6468
You can’t perform that action at this time.
0 commit comments