Skip to content

Conversation

@pblazej
Copy link
Contributor

@pblazej pblazej commented Dec 15, 2025

Resolves #866

Fixes remaining concurrency antipatterns (mostly implicit self inside a long-running Task) so that deinit (and cancel etc.) is never called.

Introduces AnyTaskCancellable wrapper for more Combine-like semantics (RAII).

⚠️ This is a global change affecting core functionality e.g. WebSocket, DataChannel, etc.

@pblazej pblazej changed the title Fix cancellation leaks Fix Task cancellation leaks Dec 15, 2025
@pblazej pblazej marked this pull request as ready for review December 17, 2025 10:11
@pblazej pblazej requested a review from hiroshihorie December 17, 2025 10:11
/// - onFailure: Called when the sequence terminates with an error. Cancellation errors are ignored.
/// - Returns: The task cancellable.
func subscribe<O: AnyObject & Sendable, State: Sendable>(
_ observer: O,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'll add some more descriptive label like subscribe(weakly: self) etc.

if let subscriber { self.noLeaks(of: subscriber) }

self.noLeaks(of: room.publisherDataChannel)
self.noLeaks(of: room.subscriberDataChannel)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiroshihorie I compared with main again and confirmed that the main leak comes from DC (its main event loop).

@pblazej
Copy link
Contributor Author

pblazej commented Jan 6, 2026

@pblazej
Copy link
Contributor Author

pblazej commented Jan 7, 2026

FYI, I added a brand-new SwiftLint rule to prevent bare Task<>

@pblazej pblazej merged commit 4845aba into main Jan 7, 2026
27 of 28 checks passed
@pblazej pblazej deleted the blaze/dc-leaks branch January 7, 2026 15:03
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.

Memory Leak in LiveKitWebRTC when streaming via BufferCapturer

3 participants