File tree Expand file tree Collapse file tree 4 files changed +31
-32
lines changed Expand file tree Collapse file tree 4 files changed +31
-32
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ package pool
3
3
import (
4
4
"bufio"
5
5
"context"
6
+ "crypto/tls"
6
7
"net"
7
8
"sync/atomic"
9
+ "syscall"
8
10
"time"
9
11
10
12
"github.com/redis/go-redis/v9/internal/proto"
@@ -17,7 +19,7 @@ type Conn struct {
17
19
netConn net.Conn
18
20
19
21
// for checking the health status of the connection, it may be nil.
20
- // sysConn syscall.Conn
22
+ sysConn syscall.Conn
21
23
22
24
rd * proto.Reader
23
25
bw * bufio.Writer
@@ -58,18 +60,18 @@ func (cn *Conn) SetNetConn(netConn net.Conn) {
58
60
}
59
61
60
62
func (cn * Conn ) setRawConn () {
61
- // cn.sysConn = nil
62
- // conn := cn.netConn
63
- // if conn == nil {
64
- // return
65
- // }
66
- // if tlsConn, ok := conn.(*tls.Conn); ok {
67
- // conn = tlsConn.NetConn()
68
- // }
69
- //
70
- // if sysConn, ok := conn.(syscall.Conn); ok {
71
- // cn.sysConn = sysConn
72
- // }
63
+ cn .sysConn = nil
64
+ conn := cn .netConn
65
+ if conn == nil {
66
+ return
67
+ }
68
+ if tlsConn , ok := conn .(* tls.Conn ); ok {
69
+ conn = tlsConn .NetConn ()
70
+ }
71
+
72
+ if sysConn , ok := conn .(syscall.Conn ); ok {
73
+ cn .sysConn = sysConn
74
+ }
73
75
}
74
76
75
77
func (cn * Conn ) Write (b []byte ) (int , error ) {
@@ -115,7 +117,7 @@ func (cn *Conn) WithWriter(
115
117
}
116
118
117
119
func (cn * Conn ) Close () error {
118
- // cn.sysConn = nil
120
+ cn .sysConn = nil
119
121
return cn .netConn .Close ()
120
122
}
121
123
Original file line number Diff line number Diff line change 3
3
package pool
4
4
5
5
import (
6
- "crypto/tls"
7
6
"errors"
8
7
"io"
9
- "net"
10
8
"syscall"
11
- "time"
12
9
)
13
10
14
11
var errUnexpectedRead = errors .New ("unexpected read from socket" )
15
12
16
- func connCheck (conn net .Conn ) error {
17
- // Reset previous timeout.
18
- _ = conn .SetDeadline (time.Time {})
19
-
20
- // Check if tls.Conn.
21
- if c , ok := conn .(* tls.Conn ); ok {
22
- conn = c .NetConn ()
23
- }
24
- sysConn , ok := conn .(syscall.Conn )
25
- if ! ok {
26
- return nil
27
- }
13
+ func connCheck (sysConn syscall .Conn ) error {
14
+ //// Reset previous timeout.
15
+ // _ = conn.SetDeadline(time.Time{})
16
+ //
17
+ //// Check if tls.Conn.
18
+ // if c, ok := conn.(*tls.Conn); ok {
19
+ // conn = c.NetConn()
20
+ // }
21
+ // sysConn, ok := conn.(syscall.Conn)
22
+ // if !ok {
23
+ // return nil
24
+ // }
28
25
rawConn , err := sysConn .SyscallConn ()
29
26
if err != nil {
30
27
return err
Original file line number Diff line number Diff line change 3
3
package pool
4
4
5
5
import (
6
- "net "
6
+ "syscall "
7
7
)
8
8
9
- func connCheck (_ net .Conn ) error {
9
+ func connCheck (_ syscall .Conn ) error {
10
10
return nil
11
11
}
Original file line number Diff line number Diff line change @@ -518,7 +518,7 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
518
518
// return false
519
519
// }
520
520
//}
521
- if connCheck (cn .netConn ) != nil {
521
+ if connCheck (cn .sysConn ) != nil {
522
522
return false
523
523
}
524
524
You can’t perform that action at this time.
0 commit comments