File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,16 @@ package internal
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"io"
6
7
"net"
7
8
"strings"
8
9
9
10
"github.com/go-redis/redis/internal/proto"
10
11
)
11
12
13
+ var ErrSingleConnPoolClosed = errors .New ("redis: SingleConnPool is closed" )
14
+
12
15
func IsRetryableError (err error , retryTimeout bool ) bool {
13
16
switch err {
14
17
case nil , context .Canceled , context .DeadlineExceeded :
@@ -22,6 +25,10 @@ func IsRetryableError(err error, retryTimeout bool) bool {
22
25
}
23
26
return true
24
27
}
28
+ if err == ErrSingleConnPoolClosed {
29
+ return true
30
+ }
31
+
25
32
s := err .Error ()
26
33
if s == "ERR max number of clients reached" {
27
34
return true
Original file line number Diff line number Diff line change 1
1
package pool
2
2
3
- import "context"
3
+ import (
4
+ "context"
5
+
6
+ "github.com/go-redis/redis/internal"
7
+ )
4
8
5
9
type SingleConnPool struct {
6
- cn * Conn
10
+ cn * Conn
11
+ cnClosed bool
7
12
}
8
13
9
14
var _ Pooler = (* SingleConnPool )(nil )
@@ -23,6 +28,9 @@ func (p *SingleConnPool) CloseConn(*Conn) error {
23
28
}
24
29
25
30
func (p * SingleConnPool ) Get (ctx context.Context ) (* Conn , error ) {
31
+ if p .cnClosed {
32
+ return nil , internal .ErrSingleConnPoolClosed
33
+ }
26
34
return p .cn , nil
27
35
}
28
36
@@ -36,9 +44,13 @@ func (p *SingleConnPool) Remove(cn *Conn) {
36
44
if p .cn != cn {
37
45
panic ("p.cn != cn" )
38
46
}
47
+ p .cnClosed = true
39
48
}
40
49
41
50
func (p * SingleConnPool ) Len () int {
51
+ if p .cnClosed {
52
+ return 0
53
+ }
42
54
return 1
43
55
}
44
56
You can’t perform that action at this time.
0 commit comments