subscription: fix producer goroutine leak on context cancel - #760
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughSubscription result forwarding now checks the execution context before each send. A regression test verifies that cancelling a blocked subscription closes the result channel and exits the producer. ChangesSubscription cancellation handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change makes subscription producers stop cleanly when their context is cancelled and adds a regression test; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
The producer in ExecuteSubscription sent results with a bare unbuffered send that did not select on p.Context.Done(). When a subscriber unsubscribes or disconnects and stops reading resultChannel, the producer blocks forever on the send; cancelling the context cannot unblock it because the goroutine is not in a select at that moment. This leaks one goroutine per unsubscribed subscription.
Wrap the send in a select that also observes p.Context.Done(), so a cancelled context lets the producer exit and close resultChannel even with no active receiver.
Add TestProducerExitsOnContextCancel as a regression test.
Summary by CodeRabbit
Bug Fixes
Tests