Skip to content

Commit 4bd6bca

Browse files
committed
fix: handle network error on SETINFO
1 parent 8fadbef commit 4bd6bca

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: redis.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
359359
p := conn.Pipeline()
360360
p.ClientSetInfo(ctx, WithLibraryName(libName))
361361
p.ClientSetInfo(ctx, WithLibraryVersion(libVer))
362-
_, _ = p.Exec(ctx)
362+
// Handle network errors (e.g. timeouts) in CLIENT SETINFO to avoid
363+
// out of order responses later on.
364+
if _, err = p.Exec(ctx); err != nil && !isRedisError(err) {
365+
return err
366+
}
363367
}
364368

365369
if c.opt.OnConnect != nil {

Diff for: redis_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ var _ = Describe("Client timeout", func() {
370370
})
371371

372372
testTimeout := func() {
373+
It("SETINFO timeouts", func() {
374+
conn := client.Conn()
375+
err := conn.Ping(ctx).Err()
376+
Expect(err).To(HaveOccurred())
377+
Expect(err.(net.Error).Timeout()).To(BeTrue())
378+
})
379+
373380
It("Ping timeouts", func() {
374381
err := client.Ping(ctx).Err()
375382
Expect(err).To(HaveOccurred())

0 commit comments

Comments
 (0)