Skip to content

Commit 2123e08

Browse files
committed
fix(internal/pool): call SetDeadline even if timeout is zero
1 parent 084c0c8 commit 2123e08

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

internal/pool/conn.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,17 @@ func (cn *Conn) RemoteAddr() net.Addr {
6464
}
6565

6666
func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error {
67-
if timeout != 0 {
68-
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
69-
return err
70-
}
67+
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
68+
return err
7169
}
7270
return fn(cn.rd)
7371
}
7472

7573
func (cn *Conn) WithWriter(
7674
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
7775
) error {
78-
if timeout != 0 {
79-
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
80-
return err
81-
}
76+
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
77+
return err
8278
}
8379

8480
if cn.bw.Buffered() > 0 {

options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type Options struct {
7676
// Default is 3 seconds.
7777
ReadTimeout time.Duration
7878
// Timeout for socket writes. If reached, commands will fail
79-
// with a timeout instead of blocking.
79+
// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
8080
// Default is ReadTimeout.
8181
WriteTimeout time.Duration
8282

0 commit comments

Comments
 (0)