Skip to content

Commit 1b26d15

Browse files
committed
test2
Signed-off-by: monkey <[email protected]>
1 parent 8cad729 commit 1b26d15

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

internal/pool/conn.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package pool
33
import (
44
"bufio"
55
"context"
6+
"crypto/tls"
67
"net"
78
"sync/atomic"
9+
"syscall"
810
"time"
911

1012
"github.com/redis/go-redis/v9/internal/proto"
@@ -17,7 +19,7 @@ type Conn struct {
1719
netConn net.Conn
1820

1921
// for checking the health status of the connection, it may be nil.
20-
//sysConn syscall.Conn
22+
sysConn syscall.Conn
2123

2224
rd *proto.Reader
2325
bw *bufio.Writer
@@ -58,18 +60,18 @@ func (cn *Conn) SetNetConn(netConn net.Conn) {
5860
}
5961

6062
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+
}
7375
}
7476

7577
func (cn *Conn) Write(b []byte) (int, error) {
@@ -115,7 +117,7 @@ func (cn *Conn) WithWriter(
115117
}
116118

117119
func (cn *Conn) Close() error {
118-
//cn.sysConn = nil
120+
cn.sysConn = nil
119121
return cn.netConn.Close()
120122
}
121123

internal/pool/conn_check.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@
33
package pool
44

55
import (
6-
"crypto/tls"
76
"errors"
87
"io"
9-
"net"
108
"syscall"
11-
"time"
129
)
1310

1411
var errUnexpectedRead = errors.New("unexpected read from socket")
1512

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+
//}
2825
rawConn, err := sysConn.SyscallConn()
2926
if err != nil {
3027
return err

internal/pool/conn_check_dummy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package pool
44

55
import (
6-
"net"
6+
"syscall"
77
)
88

9-
func connCheck(_ net.Conn) error {
9+
func connCheck(_ syscall.Conn) error {
1010
return nil
1111
}

internal/pool/pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func (p *ConnPool) isHealthyConn(cn *Conn) bool {
518518
// return false
519519
// }
520520
//}
521-
if connCheck(cn.netConn) != nil {
521+
if connCheck(cn.sysConn) != nil {
522522
return false
523523
}
524524

0 commit comments

Comments
 (0)