Skip to content

Commit af0dcd7

Browse files
committed
[ISSUE-3402]: Ring.Pipelined return dial timeout error
1 parent eb40ac8 commit af0dcd7

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

ring.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,8 @@ func (c *Ring) generalProcessPipeline(
784784
}
785785

786786
var wg sync.WaitGroup
787+
errs := make(chan error, len(cmdsMap))
788+
787789
for hash, cmds := range cmdsMap {
788790
wg.Add(1)
789791
go func(hash string, cmds []Cmder) {
@@ -796,16 +798,23 @@ func (c *Ring) generalProcessPipeline(
796798
return
797799
}
798800

801+
hook := shard.Client.processPipelineHook
799802
if tx {
800-
cmds = wrapMultiExec(ctx, cmds)
801-
_ = shard.Client.processTxPipelineHook(ctx, cmds)
802-
} else {
803-
_ = shard.Client.processPipelineHook(ctx, cmds)
803+
cmds, hook = wrapMultiExec(ctx, cmds), shard.Client.processTxPipelineHook
804+
}
805+
806+
if err = hook(ctx, cmds); err != nil {
807+
errs <- err
804808
}
805809
}(hash, cmds)
806810
}
807811

808812
wg.Wait()
813+
close(errs)
814+
815+
if err := <-errs; err != nil {
816+
return err
817+
}
809818
return cmdsFirstErr(cmds)
810819
}
811820

ring_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ var _ = Describe("Redis Ring", func() {
271271
Expect(ringShard1.Info(ctx).Val()).ToNot(ContainSubstring("keys="))
272272
Expect(ringShard2.Info(ctx).Val()).To(ContainSubstring("keys=100"))
273273
})
274+
275+
It("return dial timeout error", func() {
276+
opt := redisRingOptions()
277+
opt.DialTimeout = 250 * time.Millisecond
278+
opt.Addrs = map[string]string{"ringShardNotExist": ":1997"}
279+
ring = redis.NewRing(opt)
280+
281+
_, err := ring.Pipelined(ctx, func(pipe redis.Pipeliner) error {
282+
pipe.HSet(ctx, "key", "value")
283+
pipe.Expire(ctx, "key", time.Minute)
284+
return nil
285+
})
286+
287+
Expect(err).To(HaveOccurred())
288+
})
274289
})
275290

276291
Describe("new client callback", func() {

0 commit comments

Comments
 (0)