Skip to content

Add max data channel buffer size parameter#6

Merged
geenkel merged 6 commits into
mainfrom
eng-3351/max_data_channel_buffer_size
Jan 8, 2026
Merged

Add max data channel buffer size parameter#6
geenkel merged 6 commits into
mainfrom
eng-3351/max_data_channel_buffer_size

Conversation

@geenkel

@geenkel geenkel commented Dec 24, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@linear

linear Bot commented Dec 24, 2025

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new parameter to control the maximum buffer size for WebRTC data channels. When the buffer exceeds this limit, new data packets are dropped to prevent unbounded memory growth.

  • Adds MaxDataChannelBuffer field to ConnectParams struct
  • Implements WithMaxDataChannelBuffer option function for configuring the buffer limit
  • Adds buffer fullness check in publishDataPacket that drops messages when the limit is exceeded

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
signalling/interfaces.go Adds MaxDataChannelBuffer uint64 field to ConnectParams struct
room.go Adds WithMaxDataChannelBuffer ConnectOption function to configure the buffer limit
engine.go Implements buffer check logic in publishDataPacket that drops messages when buffer is full

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread room.go Outdated
Comment thread engine.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread engine.go
Comment thread engine.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread engine.go Outdated
Comment thread engine.go Outdated
Comment thread engine.go Outdated
Comment thread engine.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread engine.go Outdated
Comment thread engine.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread engine.go
Comment thread engine.go
@geenkel
geenkel requested a review from Hunter-Dolan December 29, 2025 14:57
Comment thread engine.go
}
if sctpBuffered+dc.BufferedAmount() > e.connParams.MaxDataChannelBuffer {
e.log.Warnw("DataChannel buffer full, dropping message", nil, "maxBufferSize", e.connParams.MaxDataChannelBuffer)
return errors.New("datachannel buffer full")

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.

Generally speaking. It's better to drop the oldest packet in the buffer, and then add the newest packet. Rather than dropping the newest packet.

Is this something we could do? Or is that too difficult? If it's too difficult it's fine to wait for this to be a problem, maybe it never will be

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To do that, we would need to modify the SCTP pion package. I think it's possible but it won't be simple. We would need to touch several parts of the SCTP logic.

I asked to copilot and he confirmed that.

Your current approach—dropping packets at the application level when Stream.BufferedAmount() or Association.BufferedAmount() exceed a threshold—is a practical way to prevent unbounded memory growth. This is a common pattern in real-time or resource-constrained systems, especially when you can tolerate some data loss (e.g., for video/audio streaming).

SCTP Standard Compliance:

  • The SCTP protocol (RFC 4960) is designed for reliable, in-order delivery by default. Dropping data at the sender before it enters the SCTP stack is not a protocol violation, but it does mean the application is responsible for handling the consequences (e.g., lost messages).
  • If you modify the SCTP package itself to drop the oldest packet in the pending queue, you would be breaking the reliability guarantee of SCTP. This is not compliant with the standard unless you are using partial reliability extensions (RFC 3758), which allow for data to be abandoned under certain conditions.

Modifying the SCTP Package:

  • If you want to implement buffer limits and drop the oldest packet in the pending queue, you would need to:
    • Add logic to track the total buffered data in the pending queues.
    • Decide which queue to drop from (ordered/unordered).
    • Ensure that sequence numbers, retransmissions, and acknowledgments are handled correctly for dropped data.
    • Possibly signal the application about dropped data.
  • This would require changes in several places: pendingQueue, stream, and possibly association logic, especially around retransmission and acknowledgment handling.

Potential Issues:

Dropping data inside the SCTP stack (without using partial reliability) breaks the protocol’s reliability guarantees and may cause confusion for peers expecting reliable delivery.
It could also cause issues with sequence numbers, retransmissions, and SACK (Selective ACK) handling.

Best Practice:

  • The best approach is usually to apply backpressure at the application level (as you are doing), so the application can decide what to drop or how to handle overload.
  • If you need to drop data within SCTP, consider implementing or using the partial reliability extension, which is designed for this purpose.

Summary:

  • Your current approach is correct and safe for memory control.
  • Modifying the SCTP package to drop data internally (without partial reliability) is not standard-compliant and would require significant changes.
  • If you need in-stack dropping, use or implement SCTP’s partial reliability features.

@geenkel
geenkel merged commit 1c4d34a into main Jan 8, 2026
7 of 12 checks passed
@geenkel
geenkel deleted the eng-3351/max_data_channel_buffer_size branch January 8, 2026 05:07
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.

3 participants