Skip to content

Commit

Permalink
stmt.Close() returns nil when double close (#1642)
Browse files Browse the repository at this point in the history
ErrBadConn needs special care to ensure it is safe to retry.
To improve maintenance, I don't want to use the error where I don't have to.

Additionally, update the old comment about Go's bug that had been fixed long time ago.
  • Loading branch information
methane authored Nov 27, 2024
1 parent 9c8d6a5 commit 2df7a26
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ type mysqlStmt struct {

func (stmt *mysqlStmt) Close() error {
if stmt.mc == nil || stmt.mc.closed.Load() {
// driver.Stmt.Close can be called more than once, thus this function
// has to be idempotent.
// See also Issue #450 and golang/go#16019.
//errLog.Print(ErrInvalidConn)
return driver.ErrBadConn
// driver.Stmt.Close could be called more than once, thus this function
// had to be idempotent. See also Issue #450 and golang/go#16019.
// This bug has been fixed in Go 1.8.
// https://github.com/golang/go/commit/90b8a0ca2d0b565c7c7199ffcf77b15ea6b6db3a
// But we keep this function idempotent because it is safer.
return nil
}

err := stmt.mc.writeCommandPacketUint32(comStmtClose, stmt.id)
Expand Down

0 comments on commit 2df7a26

Please sign in to comment.