forked from mirror/redis
fix(internal/pool): call SetDeadline even if timeout is zero
This commit is contained in:
parent
084c0c8914
commit
2123e08437
|
@ -64,22 +64,18 @@ func (cn *Conn) RemoteAddr() net.Addr {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error {
|
func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error {
|
||||||
if timeout != 0 {
|
|
||||||
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
|
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return fn(cn.rd)
|
return fn(cn.rd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cn *Conn) WithWriter(
|
func (cn *Conn) WithWriter(
|
||||||
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
|
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
|
||||||
) error {
|
) error {
|
||||||
if timeout != 0 {
|
|
||||||
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
|
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if cn.bw.Buffered() > 0 {
|
if cn.bw.Buffered() > 0 {
|
||||||
cn.bw.Reset(cn.netConn)
|
cn.bw.Reset(cn.netConn)
|
||||||
|
|
|
@ -76,7 +76,7 @@ type Options struct {
|
||||||
// Default is 3 seconds.
|
// Default is 3 seconds.
|
||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
// Timeout for socket writes. If reached, commands will fail
|
// Timeout for socket writes. If reached, commands will fail
|
||||||
// with a timeout instead of blocking.
|
// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
|
||||||
// Default is ReadTimeout.
|
// Default is ReadTimeout.
|
||||||
WriteTimeout time.Duration
|
WriteTimeout time.Duration
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue