Repository navigation
webrtc: release taken-over sessions' UDP sockets - #54
Merged
Merged
Conversation
Every taken-over session left about three UDP sockets open on the device (one ICE host candidate per local address), so rustkvm_app's fd count grew by ~3.5 per session even though pc.close() was called. webrtc-util's UdpSocket::close is a no-op; the socket only closes when its last Arc drops. The on_data_channel handler, which the peer connection owns, captured a Session clone holding Arc<RTCPeerConnection>, and DataChannelManager passed that Session on into the data channel callbacks. The connection therefore owned a reference to itself and was never dropped, keeping its ICE agent and candidate sockets alive. Give the handler a Session clone without the peer connection; data channel routing only uses the id and channels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 of 10 tasks
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.
Requested by 4c · project thread
Summary
Before: every time a browser tab took over the session, the old session's WebRTC peer connection stayed alive on the device even after
pc.close(). Each one kept about three UDP sockets open (one ICE host candidate per local address), sorustkvm_app's fd count grew by ~3.5 per session (66 → 87 → 108 over two rounds of six take-overs in the round-4 web UI test).After: the old peer connection is dropped once it is closed and removed, so its ICE agent and candidate sockets are released.
webrtc-util's
UdpSocket::closeis a no-op; a UDP conn only closes when its lastArcdrops. Theon_data_channelhandler, owned by the peer connection, captured aSessionclone holdingArc<RTCPeerConnection>, andDataChannelManagerpassed thatSessionon into the data channel callbacks. The connection therefore held a reference to itself and was never dropped.How
app/src/webrtc.rs: theon_data_channelhandler now gets aSessionclone withpeer_connection = None. Data channel routing only uses the session id and channels; the only users ofSession::peer_connection(exchange_offer,add_ice_candidate, and the take-over close inwebrtc_handlers.rs/webrtc.rs) read theSessionstored inAppState, which still holds the connection.Testing
cargo +nightly fmt --all(CI)cargo +nightly clippy --workspace --release --all-targets -- -D warnings(CI)cargo +nightly test --workspace(CI)Checklist
#[allow(...)]suppressions and no newunwrap()/expect()in production pathsMissedTickBehavior::Delayrkvm-protoFollow-up to #53, which fixed the browser-side WebSocket leak; this is the device-side fd leak found in the same test.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PbdzY6PfT28goR4BhqdsXR