From 2123e084376cfc93be6e28d6308a008f97d2fd16 Mon Sep 17 00:00:00 2001 From: jianghang Date: Wed, 3 Aug 2022 22:43:37 +0800 Subject: [PATCH] fix(internal/pool): call SetDeadline even if timeout is zero --- internal/pool/conn.go | 12 ++++-------- options.go | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/internal/pool/conn.go b/internal/pool/conn.go index a760be2..5b5079a 100644 --- a/internal/pool/conn.go +++ b/internal/pool/conn.go @@ -64,10 +64,8 @@ func (cn *Conn) RemoteAddr() net.Addr { } 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 { - return err - } + if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil { + return err } return fn(cn.rd) } @@ -75,10 +73,8 @@ func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(r func (cn *Conn) WithWriter( ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error, ) error { - if timeout != 0 { - if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil { - return err - } + if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil { + return err } if cn.bw.Buffered() > 0 { diff --git a/options.go b/options.go index 8f5f380..0c2cb1d 100644 --- a/options.go +++ b/options.go @@ -76,7 +76,7 @@ type Options struct { // Default is 3 seconds. ReadTimeout time.Duration // 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. WriteTimeout time.Duration