MCPcopy
hub / github.com/go-sql-driver/mysql / ResetSession

Method ResetSession

connection.go:777–807  ·  view source on GitHub ↗

ResetSession implements driver.SessionResetter. (From Go 1.10)

(ctx context.Context)

Source from the content-addressed store, hash-verified

775// ResetSession implements driver.SessionResetter.
776// (From Go 1.10)
777func (mc *mysqlConn) ResetSession(ctx context.Context) error {
778 if mc.closed.Load() || mc.buf.busy() {
779 return driver.ErrBadConn
780 }
781
782 // Perform a stale connection check. We only perform this check for
783 // the first query on a connection that has been checked out of the
784 // connection pool: a fresh connection from the pool is more likely
785 // to be stale, and it has not performed any previous writes that
786 // could cause data corruption, so it's safe to return ErrBadConn
787 // if the check fails.
788 if mc.cfg.CheckConnLiveness {
789 conn := mc.netConn
790 if mc.rawConn != nil {
791 conn = mc.rawConn
792 }
793 var err error
794 if mc.cfg.ReadTimeout != 0 {
795 err = conn.SetReadDeadline(time.Now().Add(mc.cfg.ReadTimeout))
796 }
797 if err == nil {
798 err = connCheck(conn)
799 }
800 if err != nil {
801 mc.log("closing bad idle connection: ", err)
802 return driver.ErrBadConn
803 }
804 }
805
806 return nil
807}
808
809// IsValid implements driver.Validator interface
810// (From Go 1.15)

Callers

nothing calls this directly

Calls 4

logMethod · 0.95
busyMethod · 0.80
connCheckFunction · 0.70
SetReadDeadlineMethod · 0.45

Tested by

no test coverage detected