Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do applications know a DataChannel's buffer capacity, so they can avoid filling it? #1148

Closed
taylor-b opened this issue Apr 29, 2017 · 1 comment · Fixed by #1209
Closed
Assignees

Comments

@taylor-b
Copy link
Contributor

A well-behaving application that sends a large amount of data will use the "bufferedAmount" event and "bufferedAmountLowThreshold", to ensure it doesn't fill the DataChannel's buffer and cause the channel to be closed.

But how does the application know what to set "bufferedAmountLowThreshold" to? If the spec doesn't provide any guarantees about an implementation's buffer size, the application developer is forced to research how large different browsers' buffers are, pick a value low enough, and hope the browser buffers don't get smaller.

So I'd suggest either:

  • Providing a bufferSize attribute (pretty straightforward)
  • Guarantee something about the buffer size. For example, "it MUST be N MB or larger".
  • Get rid of the "data channel closing on buffer filling" behavior, and just throw/return an error instead, like a non-blocking socket. This is a more radical change, but is anyone really attached to the current behavior? It seems to cause a fair amount of confusion. See discussion here: https://groups.google.com/forum/#!topic/discuss-webrtc/apmq9VLY9lc
@stefhak
Copy link
Contributor

stefhak commented May 4, 2017

I think this part is modeled after the web socket behavior (https://html.spec.whatwg.org/multipage/comms.html#dom-websocket-send). We could probably do better, but isn't this "standard" behavior, e.g. you can't find out how big objects you can post using fetch or xhr?

taylor-b added a commit to taylor-b/webrtc-pc that referenced this issue May 12, 2017
Fixes w3c#1148.

This is option #1 for fixing the issue. An application can read this
bufferSize attribute, and check "messageSize + bufferedAmount <=
bufferSize" before sending data to ensure it won't abruptly close the
data channel.
taylor-b added a commit to taylor-b/webrtc-pc that referenced this issue May 12, 2017
Fixes w3c#1148.

Option 2 for fixing the issue. The application doesn't need to know the
buffer's size ahead of time, because filling the buffer is no longer an
irrecoverable error. If it doesn't care about latency, an application
could send until an exception is thrown, then wait for the
"bufferedamountlow" event until it can send again, similar to a
non-blocking socket.

Note that this is deliberately different than how WebSockets work,
because the circumstances are slightly different: with WebSockets, it
was expected that applications had code to handle them being closed
unexpectedly. But this isn't true of WebRTC DataChannels, because before
an SCTP-level timeout can occur, the application would have done an ICE
restart and repaired the problem.
@aboba aboba closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants