Skip to content

fix(peer_connection): implement SCTP/DataChannel close on PeerConnection shutdown#76

Open
nightness wants to merge 1 commit intowebrtc-rs:masterfrom
Brainwires:fix/peerconnection-close
Open

fix(peer_connection): implement SCTP/DataChannel close on PeerConnection shutdown#76
nightness wants to merge 1 commit intowebrtc-rs:masterfrom
Brainwires:fix/peerconnection-close

Conversation

@nightness
Copy link
Copy Markdown

Summary

  • SctpHandler::close(): was a no-op (Ok(())). Now iterates all SCTP associations, calls assoc.close(AssociationError::LocallyClosed) on each, clears the associations map, and drops the endpoint.
  • DataChannelHandler::close(): was a no-op. Now calls dc.close() on each RTCDataChannelInternal (transitions state to Closed, closes the underlying SCTP stream), then clears the data channels map.
  • handler/mod.rs: removes the stale ~40-line async-era /* TODO: */ comment block that used .await syntax incompatible with this synchronous sans-IO handler. Replaced with a concise comment mapping each W3C close step to the handler that implements it.

ICE (IceHandler::close()agent.close()), DTLS (DtlsHandler::close()dtls_transport.stop()), and interceptor (InterceptorHandler::close()interceptor.close()) were already correctly implemented.

Test plan

  • cargo test -p rtc — all 246 tests pass
  • Integration: open a DataChannel, close the PeerConnection, verify the channel transitions to Closed state and no SCTP timers remain running

🤖 Generated with Claude Code

…ion shutdown

SctpHandler::close() and DataChannelHandler::close() both returned Ok(()) without
actually closing anything. On PeerConnection close, SCTP associations were left in
a running state and data channels were never transitioned to Closed.

- SctpHandler::close(): close all SCTP associations with LocallyClosed reason,
  then clear the associations map and drop the endpoint.
- DataChannelHandler::close(): close each RTCDataChannelInternal instance
  (sets ready_state → Closed, closes underlying data channel stream), then
  clear the data channels map.
- handler/mod.rs: remove stale async-era TODO comment block that cannot compile
  in this synchronous sans-IO handler; replace with a comment documenting which
  handler handles which W3C close step.

ICE, DTLS, and interceptor close were already correctly implemented in their
respective handlers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nightness nightness force-pushed the fix/peerconnection-close branch from d7d5a8b to 58c9cf4 Compare April 1, 2026 18:43
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