Skip to content

Release abandoned subject subscriptions and eliminate leaked test consumers - #67

Merged
twittemb merged 2 commits into
mainfrom
codex/fix-subject-subscription-lifetime
Oct 3, 2026
Merged

twittemb merged 2 commits into
mainfrom
codex/fix-subject-subscription-lifetime

Conversation

@twittemb

@twittemb twittemb commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • The iterator-lifetime regression failed for all six subjects before the fix.
  • All 175 tests pass, including concurrent send ordering and cancellation/deadlock regressions.
  • The cited AsyncCurrentValueSubjectTests.test_send_pushes_values_in_the_subject changed from two leaked allocations to 0 leaks / 0 bytes under leaks --atExit.
  • A full-suite leak scan reports no subject/channel allocations. It still reports two 16-byte 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.

@twittemb
twittemb force-pushed the codex/fix-subject-subscription-lifetime branch from c91c178 to d501747 Compare October 3, 2026 11:45
@twittemb
twittemb merged commit ee4b99d into main Oct 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] possible memory leak in AsyncBufferedChannel

1 participant