Skip to content

Commit

Permalink
Conn timeout should be higher than read timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jul 22, 2018
1 parent ee41b90 commit b92dacb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ func (c *ClusterClient) remapCmds(cmds []Cmder, failedCmds map[*clusterNode][]Cm
func (c *ClusterClient) pipelineProcessCmds(
node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder,
) error {
_ = cn.SetWriteTimeout(c.opt.WriteTimeout)
cn.SetWriteTimeout(c.opt.WriteTimeout)

err := writeCmd(cn, cmds...)
if err != nil {
Expand All @@ -1284,7 +1284,7 @@ func (c *ClusterClient) pipelineProcessCmds(
}

// Set read timeout for all commands.
_ = cn.SetReadTimeout(c.opt.ReadTimeout)
cn.SetReadTimeout(c.opt.ReadTimeout)

return c.pipelineReadCmds(cn, cmds, failedCmds)
}
Expand Down
8 changes: 4 additions & 4 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (c *cmdable) Migrate(host, port, key string, db int64, timeout time.Duratio
db,
formatMs(timeout),
)
cmd.setReadTimeout(readTimeout(timeout))
cmd.setReadTimeout(timeout)
c.process(cmd)
return cmd
}
Expand Down Expand Up @@ -995,7 +995,7 @@ func (c *cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
}
args[len(args)-1] = formatSec(timeout)
cmd := NewStringSliceCmd(args...)
cmd.setReadTimeout(readTimeout(timeout))
cmd.setReadTimeout(timeout)
c.process(cmd)
return cmd
}
Expand All @@ -1008,7 +1008,7 @@ func (c *cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
}
args[len(keys)+1] = formatSec(timeout)
cmd := NewStringSliceCmd(args...)
cmd.setReadTimeout(readTimeout(timeout))
cmd.setReadTimeout(timeout)
c.process(cmd)
return cmd
}
Expand All @@ -1020,7 +1020,7 @@ func (c *cmdable) BRPopLPush(source, destination string, timeout time.Duration)
destination,
formatSec(timeout),
)
cmd.setReadTimeout(readTimeout(timeout))
cmd.setReadTimeout(timeout)
c.process(cmd)
return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
return nil, err
}

cn.SetReadTimeout(timeout)
cn.SetReadTimeout(readTimeout(timeout))
err = c.cmd.readReply(cn)
c.releaseConn(cn, err)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ func (c *baseClient) retryBackoff(attempt int) time.Duration {

func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration {
if timeout := cmd.readTimeout(); timeout != nil {
return *timeout
return readTimeout(*timeout)
}

return c.opt.ReadTimeout
}

Expand Down

0 comments on commit b92dacb

Please sign in to comment.