Release abandoned subject subscriptions and eliminate leaked test consumers - #67
Merged
Merged
Conversation
twittemb
force-pushed
the
codex/fix-subject-subscription-lifetime
branch
from
October 3, 2026 11:45
c91c178 to
d501747
Compare
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.
The subject tests cited in #43 left consumer tasks awaiting channels after the tests ended. Those tests now finish their subjects and await their consumer tasks. Subject iterators also unregister when their last copy is released, so an early loop exit or abandoned iterator no longer leaves a subscriber channel buffering future values.
A shared registration token preserves iterator-copy semantics and existing cancellation handling across all six subject types. Regressions prove that the last iterator copy unregisters and that abandoned passthrough iterators release buffered reference values. Documents the consuming task's lifetime responsibility.
Validation on Swift 6.4/macOS:
AsyncCurrentValueSubjectTests.test_send_pushes_values_in_the_subjectchanged from two leaked allocations to 0 leaks / 0 bytes underleaks --atExit.Lock.allocate()allocations in the Swift Async Algorithms 1.0.0 dependency, reached by the two- and three-input merge compatibility tests. Those dependency allocations are outside this PR's subject lifetime fix.Fixes #43.