Skip to content

Commit

Permalink
Merge pull request #139 from hdonnay/bug/subscription-close
Browse files Browse the repository at this point in the history
stomp: fix Unsubscribe race
  • Loading branch information
worg authored Oct 24, 2024
2 parents 9a13a1a + 9165d8a commit 80a8c9f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ func (s *Subscription) Unsubscribe(opts ...func(*frame.Frame) error) error {
for atomic.LoadInt32(&s.state) != subStateClosed {
err = waitWithTimeout(s.closeCond, s.unsubscribeReceiptTimeout)
if err != nil && errors.Is(err, &ErrUnsubscribeReceiptTimeout) {
msg := s.subscriptionErrorMessage("channel unsubscribe receipt timeout")
s.C <- msg
// The [closeCond.Broadcast] can race with the timeout, so make sure
// the channel is still available.
if atomic.LoadInt32(&s.state) != subStateClosed {
msg := s.subscriptionErrorMessage("channel unsubscribe receipt timeout")
s.C <- msg
}
return err
}
}
Expand Down

0 comments on commit 80a8c9f

Please sign in to comment.