Skip to content

Commit 503d80c

Browse files
committed
Fix PubSub.Ping to hold the lock
1 parent 917c476 commit 503d80c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pubsub.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,16 @@ func (c *PubSub) Ping(ctx context.Context, payload ...string) error {
252252
}
253253
cmd := NewCmd(ctx, args...)
254254

255-
cn, err := c.connWithLock(ctx)
255+
c.mu.Lock()
256+
defer c.mu.Unlock()
257+
258+
cn, err := c.conn(ctx, nil)
256259
if err != nil {
257260
return err
258261
}
259262

260263
err = c.writeCmd(ctx, cn, cmd)
261-
c.releaseConnWithLock(ctx, cn, err, false)
264+
c.releaseConn(ctx, cn, err, false)
262265
return err
263266
}
264267

@@ -361,6 +364,8 @@ func (c *PubSub) ReceiveTimeout(ctx context.Context, timeout time.Duration) (int
361364
c.cmd = NewCmd(ctx)
362365
}
363366

367+
// Don't hold the lock to allow subscriptions and pings.
368+
364369
cn, err := c.connWithLock(ctx)
365370
if err != nil {
366371
return nil, err
@@ -371,6 +376,7 @@ func (c *PubSub) ReceiveTimeout(ctx context.Context, timeout time.Duration) (int
371376
})
372377

373378
c.releaseConnWithLock(ctx, cn, err, timeout > 0)
379+
374380
if err != nil {
375381
return nil, err
376382
}

0 commit comments

Comments
 (0)