Merge pull request #817 from go-redis/fix/pubsub-read-timeout

Conn timeout should be higher than read timeout
This commit is contained in:
Vladimir Mihailenco 2018-07-22 09:17:41 +03:00 committed by GitHub
commit 585aea1e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 9 deletions

View File

@ -1274,7 +1274,7 @@ func (c *ClusterClient) remapCmds(cmds []Cmder, failedCmds map[*clusterNode][]Cm
func (c *ClusterClient) pipelineProcessCmds( func (c *ClusterClient) pipelineProcessCmds(
node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder, node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder,
) error { ) error {
_ = cn.SetWriteTimeout(c.opt.WriteTimeout) cn.SetWriteTimeout(c.opt.WriteTimeout)
err := writeCmd(cn, cmds...) err := writeCmd(cn, cmds...)
if err != nil { if err != nil {
@ -1284,7 +1284,7 @@ func (c *ClusterClient) pipelineProcessCmds(
} }
// Set read timeout for all commands. // Set read timeout for all commands.
_ = cn.SetReadTimeout(c.opt.ReadTimeout) cn.SetReadTimeout(c.opt.ReadTimeout)
return c.pipelineReadCmds(cn, cmds, failedCmds) return c.pipelineReadCmds(cn, cmds, failedCmds)
} }

View File

@ -421,7 +421,7 @@ func (c *cmdable) Migrate(host, port, key string, db int64, timeout time.Duratio
db, db,
formatMs(timeout), formatMs(timeout),
) )
cmd.setReadTimeout(readTimeout(timeout)) cmd.setReadTimeout(timeout)
c.process(cmd) c.process(cmd)
return cmd return cmd
} }
@ -995,7 +995,7 @@ func (c *cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
} }
args[len(args)-1] = formatSec(timeout) args[len(args)-1] = formatSec(timeout)
cmd := NewStringSliceCmd(args...) cmd := NewStringSliceCmd(args...)
cmd.setReadTimeout(readTimeout(timeout)) cmd.setReadTimeout(timeout)
c.process(cmd) c.process(cmd)
return cmd return cmd
} }
@ -1008,7 +1008,7 @@ func (c *cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
} }
args[len(keys)+1] = formatSec(timeout) args[len(keys)+1] = formatSec(timeout)
cmd := NewStringSliceCmd(args...) cmd := NewStringSliceCmd(args...)
cmd.setReadTimeout(readTimeout(timeout)) cmd.setReadTimeout(timeout)
c.process(cmd) c.process(cmd)
return cmd return cmd
} }
@ -1020,7 +1020,7 @@ func (c *cmdable) BRPopLPush(source, destination string, timeout time.Duration)
destination, destination,
formatSec(timeout), formatSec(timeout),
) )
cmd.setReadTimeout(readTimeout(timeout)) cmd.setReadTimeout(timeout)
c.process(cmd) c.process(cmd)
return cmd return cmd
} }

View File

@ -309,7 +309,7 @@ func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
return nil, err return nil, err
} }
cn.SetReadTimeout(timeout) cn.SetReadTimeout(readTimeout(timeout))
err = c.cmd.readReply(cn) err = c.cmd.readReply(cn)
c.releaseConn(cn, err) c.releaseConn(cn, err)
if err != nil { if err != nil {

View File

@ -176,9 +176,8 @@ func (c *baseClient) retryBackoff(attempt int) time.Duration {
func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration { func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration {
if timeout := cmd.readTimeout(); timeout != nil { if timeout := cmd.readTimeout(); timeout != nil {
return *timeout return readTimeout(*timeout)
} }
return c.opt.ReadTimeout return c.opt.ReadTimeout
} }