Skip to content

fix(audio): the tap continuation's weak capture sat on the wrong closure - #350

Merged
superuser404notfound merged 1 commit into
mainfrom
fix/audio-tap-termination-capture
Aug 9, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
fix/audio-tap-termination-capture

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

AudioTapController.makeStream wrote [weak self] on the Task inside cont.onTermination. The outer closure captured self strongly regardless, so the continuation this controller owns retained the controller back. Swift 6.3 flags it as #ImplicitStrongCapture; it showed up in @jihongboo's Xcode 27 beta build log on #313 and is unrelated to the SDK isolation thread there.

Not a leak in the shipped paths: removeAudioTap, load and stop all go through teardown(), which finishes the continuation and drops the handler. What the misplaced capture cost was the guarantee it appeared to give, a path that released the controller without tearing down would have kept the reader running instead of stopping it.

Moving the capture to the outer closure makes the declared intent the real one. teardown() is idempotent, so termination landing after teardown with a nil self is a no-op.

swift build clean, swift test --filter AudioTap 37/37.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE

Surfaced by @jihongboo's Xcode 27 beta build log on #313, unrelated to the
SDK isolation thread it came from: ImplicitStrongCapture flags that the
`[weak self]` on the inner Task was decorative. The outer onTermination
closure captured `self` strongly anyway, so the controller's own
continuation retained the controller back.

Not a leak today, because every path (removeAudioTap, load, stop) releases
the controller through `teardown()`, which finishes the continuation and
drops the handler. What it cost was the guarantee the annotation claimed:
a path that dropped the controller without tearing down would have kept
the reader running rather than stopping it, and the code read as if it
could not.

Moving the capture to the outer closure makes the declared intent the
actual one. `teardown()` is idempotent, so a nil `self` when termination
lands after teardown is a no-op.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
@superuser404notfound
superuser404notfound merged commit c5eb309 into main Aug 9, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/audio-tap-termination-capture branch August 9, 2026 13:46
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.

1 participant