Replies: 5 comments 7 replies
-
Hi @terut, I believe it is safe to do Maybe scheduling a timer to close the Line 329 in bd17103 |
Beta Was this translation helpful? Give feedback.
-
Thank you for reply. That sounds good and it's better idea than mine. I tried that approach. Probably is it like this? // pipe.go
func _newPipe(connFn func() (net.Conn, error), option *ClientOption, r2ps, nobg bool) (p *pipe, err error) {
// ...
go func() {
<-time.After(10 * time.Second)
p.Close()
}()
} This approach sometimes occurred error such "rueidis client is closing or unable to connect redis" and stopped the process keeps going to call commands. Read-only command is no problem because it are retryable, but write command cannot retry. It maybe be harder than I thought. I completely thought that Shoud I check Line 136 in c586d3c |
Beta Was this translation helpful? Give feedback.
-
Checking p.state there doesn’t help. We may need a special error and let writes can retry on it. |
Beta Was this translation helpful? Give feedback.
-
Okay. Thank you for your advice. How is this? // pipe.go
func _newPipe(connFn func() (net.Conn, error), option *ClientOption, r2ps, nobg bool) (p *pipe, err error) {
// ...
go func() {
<-time.After(5 * time.Second) // depends on MaxConnLifetime option
p.expired()
}()
}
func (p *pipe) expired() {
p.error.CompareAndSwap(nil, errExpired)
p.Close()
}
var errExpired = &errs{error: ErrExpiredConnection} // client.go
func (c *singleClient) Do(ctx context.Context, cmd Completed) (resp RedisResult) {
attempts := 1
retry:
resp = c.conn.Do(ctx, cmd)
if resp.Error() == ErrExpiredConnection { // force retry
goto retry
}
if c.retry && cmd.IsReadOnly() && c.isRetryable(resp.Error(), ctx) {
// ...
}
//...
} For now, I feel like it's working well on concurrent processing about both reads and writes. |
Beta Was this translation helpful? Give feedback.
-
@rueian @terut
If i'm correct, We should fix three things first.
I don't understand how In some respects, closing connections and swapping new connection act like |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you for writing great library. It is working well for now !
Recently I noticed that request is unbalanced when its replica failover on a cloud service if the connection keeps. So I consider about connection lifetime to reconnect to redis endpoint because existing connection are not rerouted when a node reintroduced.
Here is the document about archtecture and connection balance manegement.
https://cloud.google.com/memorystore/docs/redis/about-read-replicas#architecture
https://cloud.google.com/memorystore/docs/redis/about-read-replicas#connection_balance_management
Other library like go-redis and redigo has a option such as
MaxConnectionLifetime
to drop expired connection from connection pool. So I tried to writing the implement of connection lifetime, but rueidis has auto pipelining is working background and detecting to finish all commands is difficult for me. Background worker for auto piplining keep going to received commands until error occurred, right?I'm glad if I know the wire is safe to close like the following.
Please tell me you have any solution about that. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions