Skip to content

Commit

Permalink
If ctx present do a select around the rwait
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Mar 17, 2022
1 parent 7fe8192 commit ba55e15
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion js.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,14 @@ func (js *js) PublishMsg(m *Msg, opts ...PubOpt) (*PubAck, error) {
if err != nil {
for r, ttl := 0, o.ttl; err == ErrNoResponders && r < o.rnum; r++ {
// To protect against small blips in leadership changes etc, if we get a no responders here retry.
time.Sleep(o.rwait)
if o.ctx != nil {
select {
case <-o.ctx.Done():
case <-time.After(o.rwait):
}
} else {
time.Sleep(o.rwait)
}
if o.ttl > 0 {
ttl -= o.rwait
if ttl <= 0 {
Expand Down

0 comments on commit ba55e15

Please sign in to comment.