Fix crash when onNext is called on disposed subscription#6126
Conversation
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
SDK Size Comparison 📏
|
|
|
Caution Review failedThe pull request is closed. WalkthroughThis pull request fixes a crash that occurred when Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |



🎯 Goal
Fix a race condition crash that occurs when
onNextis called on a subscription that has already been disposed:The crash happens due to a TOCTOU (time-of-check to time-of-use) race condition between:
ChatEventsObservable.notifySubscriptions()checkingsubscription.isDisposed→ returnsfalsesubscription.dispose()→ setsisDisposed = truenotifySubscriptions()callingsubscription.onNext(event)→check(!isDisposed)throws🛠 Implementation details
check(!isDisposed)withif (isDisposed) returnin bothSubscriptionImplandSuspendSubscriptionlistener?.onEvent()safe call provides additional safety iflistenerbecomes null mid-execution🎨 UI Changes
No UI changes.
🧪 Testing
Summary by CodeRabbit
onNextis called on a disposed subscription. The app now gracefully handles this scenario instead of throwing an exception.