Repository navigation
Release a dropped stream's subscription or timer - #61
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
subscribe()andcreate_timer()hand the subscription / timer to the returned stream (stream->sub_,stream->timer_), while the callback they register captures the same stream as ashared_ptr. The two keep each other alive, so dropping the stream never releases them: the subscription stays registered and keeps queueing messages nobody reads, and the timer keeps firing.poll_until()creates a timer on every wait that does not succeed at once, sowait_for_service()/wait_for_action()leave one behind each time they have to wait.The callbacks now hold the stream weakly. Dropping the stream (e.g. at the end of the coroutine that created it, as in the guide's examples) releases the subscription or timer with it; a coroutine awaiting
next()still owns the stream, so it is not released under it.Tests added:
TopicStreamTest.DroppingTheStreamUnsubscribes: the stream expires andcount_subscribers()drops back to 0TimerStreamTest.DroppingTheStreamReleasesTheTimerWaitForServiceTest.TimeoutLeavesNoTimerBehind: no timer is left on the node after a timed-outwait_for_service()All three fail without the change and pass with it.