Skip to content

Reject oversized data messages before they break the data channel#1137

Open
cnderrauber wants to merge 3 commits into
mainfrom
datamessage_size
Open

Reject oversized data messages before they break the data channel#1137
cnderrauber wants to merge 3 commits into
mainfrom
datamessage_size

Conversation

@cnderrauber
Copy link
Copy Markdown
Contributor

Sending a data message larger than the negotiated SCTP max message size made libwebrtc abruptly close the publisher data channel. Because DataChannelInterface::Send returns true regardless, publish_data() returned Ok while the channel was silently torn down; every subsequent publish then failed with "could not establish publisher connection: timeout" (15s each) since the channel is never recreated once has_published is set.

  • Parse the negotiated max message size from the publisher answer SDP (RFC 8841 a=max-message-size), defaulting to 65535 when absent.
  • Reject packets whose encoded size exceeds it in publish_data(), returning an error to the caller instead of silently aborting the channel. A value of 0 means "no limit".
  • Log an info when a publisher data channel closes while the session and peer connection are still up (the signature of this failure), without attempting renegotiation.

Sending a data message larger than the negotiated SCTP max message size
made libwebrtc abruptly close the publisher data channel. Because
DataChannelInterface::Send returns true regardless, publish_data() returned
Ok while the channel was silently torn down; every subsequent publish then
failed with "could not establish publisher connection: timeout" (15s each)
since the channel is never recreated once has_published is set.

- Parse the negotiated max message size from the publisher answer SDP
  (RFC 8841 a=max-message-size), defaulting to 65535 when absent.
- Reject packets whose encoded size exceeds it in publish_data(), returning
  an error to the caller instead of silently aborting the channel. A value
  of 0 means "no limit".
- Log an info when a publisher data channel closes while the session and
  peer connection are still up (the signature of this failure), without
  attempting renegotiation.
@cnderrauber cnderrauber requested a review from ladvoc as a code owner June 5, 2026 10:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Changeset

The following package versions will be affected by this PR:

Package Bump
livekit patch
livekit-ffi patch

Comment thread livekit/src/rtc_engine/rtc_session.rs Outdated
return;
};
if !inner.closed.load(Ordering::Acquire) && inner.publisher_pc.is_connected() {
log::info!(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: This should probably be logged at error level.

// Log when a publisher data channel closes without the engine or peer
// connection tearing it down
for (dc, label) in
[(&inner.reliable_dc, RELIABLE_DC_LABEL), (&inner.lossy_dc, LOSSY_DC_LABEL)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: For completeness, this should probably also track the data track DC.

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.

2 participants