File tree 2 files changed +25
-30
lines changed
2 files changed +25
-30
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ type mysqlConn struct {
34
34
status statusFlag
35
35
sequence uint8
36
36
parseTime bool
37
- reset bool // set when the Go SQL package calls ResetSession
38
37
39
38
// for context support (Go 1.8+)
40
39
watching bool
@@ -646,7 +645,31 @@ func (mc *mysqlConn) ResetSession(ctx context.Context) error {
646
645
if mc .closed .Load () {
647
646
return driver .ErrBadConn
648
647
}
649
- mc .reset = true
648
+
649
+ // Perform a stale connection check. We only perform this check for
650
+ // the first query on a connection that has been checked out of the
651
+ // connection pool: a fresh connection from the pool is more likely
652
+ // to be stale, and it has not performed any previous writes that
653
+ // could cause data corruption, so it's safe to return ErrBadConn
654
+ // if the check fails.
655
+ if mc .cfg .CheckConnLiveness {
656
+ conn := mc .netConn
657
+ if mc .rawConn != nil {
658
+ conn = mc .rawConn
659
+ }
660
+ var err error
661
+ if mc .cfg .ReadTimeout != 0 {
662
+ err = conn .SetReadDeadline (time .Now ().Add (mc .cfg .ReadTimeout ))
663
+ }
664
+ if err == nil {
665
+ err = connCheck (conn )
666
+ }
667
+ if err != nil {
668
+ mc .cfg .Logger .Print ("closing bad idle connection: " , err )
669
+ return driver .ErrBadConn
670
+ }
671
+ }
672
+
650
673
return nil
651
674
}
652
675
Original file line number Diff line number Diff line change @@ -98,34 +98,6 @@ func (mc *mysqlConn) writePacket(data []byte) error {
98
98
return ErrPktTooLarge
99
99
}
100
100
101
- // Perform a stale connection check. We only perform this check for
102
- // the first query on a connection that has been checked out of the
103
- // connection pool: a fresh connection from the pool is more likely
104
- // to be stale, and it has not performed any previous writes that
105
- // could cause data corruption, so it's safe to return ErrBadConn
106
- // if the check fails.
107
- if mc .reset {
108
- mc .reset = false
109
- conn := mc .netConn
110
- if mc .rawConn != nil {
111
- conn = mc .rawConn
112
- }
113
- var err error
114
- if mc .cfg .CheckConnLiveness {
115
- if mc .cfg .ReadTimeout != 0 {
116
- err = conn .SetReadDeadline (time .Now ().Add (mc .cfg .ReadTimeout ))
117
- }
118
- if err == nil {
119
- err = connCheck (conn )
120
- }
121
- }
122
- if err != nil {
123
- mc .cfg .Logger .Print ("closing bad idle connection: " , err )
124
- mc .Close ()
125
- return driver .ErrBadConn
126
- }
127
- }
128
-
129
101
for {
130
102
var size int
131
103
if pktLen >= maxPacketSize {
You can’t perform that action at this time.
0 commit comments