Repository navigation
Join a subscription's handler before releasing the caller's reference - #181
Merged
Merged
Conversation
An async subscription that reaches its autounsubscribe limit removes itself from the connection on its own handler task. If the caller had already released its reference, that removal dropped the last one, and destroy() then joined the handler task from inside that same task, which never returns. Connection.deinit() later reported it as a live subscription the caller had not released. deinit() now stops the handler while the caller's reference still keeps the subscription alive, so the handler can never drop the last one.
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (1)
✨ 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 |
lalinsky
added a commit
that referenced
this pull request
Oct 6, 2026
…#181) An async subscription that reaches its autounsubscribe limit removes itself from the connection on its own handler task. If the caller had already released its reference, that removal dropped the last one, and destroy() then joined the handler task from inside that same task, which never returns. Connection.deinit() later reported it as a live subscription the caller had not released. deinit() now stops the handler while the caller's reference still keeps the subscription alive, so the handler can never drop the last one.
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.
A smaller fix for the
autounsubscribe async basic functionalityflake. It replaces #179.The bug
An async subscription that reaches its autounsubscribe limit calls
removeSubscriptionInternalon its own handler task, which drops the connection's reference. If the caller has already calledsub.deinit(), that reference is the last one. The release runsdestroy(), which joins the handler task group from inside that same task, so it never returns.Connection.deinit()then panics with1 live subscription(s).The fix
Subscription.deinit()closes the queue and joins the handler before it unsubscribes and drops the caller's reference. The handler can then never be the one that drops the last reference.destroy()still runs the same close and cancel, which do nothing on the second call.Unlike #179, this leaves
live_subscriptionsand the panic for unreleased subscriptions unchanged. The other library code that drops subscription references runs on connection tasks thatclose()joins before that check.Calling
sub.deinit()from the subscription's own handler is documented as not allowed. It was already a self-join in most cases.Testing
autounsubscribetests: 7 failures in 10 runs onmain, 0 in 50 runs with this change../check.shpasses.