Skip to content

Commit

Permalink
[FIXED] Switch to atomic CAS to eliminate race condition in pull subs…
Browse files Browse the repository at this point in the history
…cription closed check (#1454)
  • Loading branch information
evanofslack authored Dec 1, 2023
1 parent 48e070d commit 4af26aa
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions jetstream/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,9 @@ func (hb *hbMonitor) Reset(dur time.Duration) {
}

func (s *pullSubscription) Stop() {
if atomic.LoadUint32(&s.closed) == 1 {
if !atomic.CompareAndSwapUint32(&s.closed, 0, 1) {
return
}
atomic.StoreUint32(&s.closed, 1)
close(s.done)
if s.consumeOpts.stopAfterMsgsLeft != nil {
if s.delivered >= s.consumeOpts.StopAfter {
Expand Down

0 comments on commit 4af26aa

Please sign in to comment.