-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, this is great. Following up from my comment #144 (comment) could you refactor this to exclude the optional maxMsgSize
and instead include the changes that ensure the underlying buffer doesn't exceed the max size of 16kb.
This should solve #158
b91dbc4
to
f15207e
Compare
I have now rebased and hardcoded 16kb limit |
|
Yes. I am not fully confident what the limits should be, and it is quite hard to tests, frankly. I made this decision reading various threads about sending large files over WebRTC and what has been done to circumvent issues. Max buffered amount should maybe be 16 Mbytes instead Some other discussion
Yes
Not sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of buffering, you can slow down the ingestion of new data from the source in the _sink
method using p-event:
for await (const buf of merge(closeWrite, src)) {
if (channel.bufferedAmount > maxMsgSize) { // this should really be maxBufferedAmountSize
await pEvent(this.channel, 'bufferedamountlow', {
timeout: // a sensible timeout
})
}
// now write message as normal
//... chunk using maxMsgSize
There's no need to buffer anything then as backpressure is implicitly applied since we stop pulling from the incoming source.
When sending the message you can then limit the max size of individual message by doing chunking in a similar way to mplex.
This should also have separate maxBufferedAmountSize
and maxMsgSize
config options since they control different things.
716e61a
to
c3fda66
Compare
Thats a great idea. I made the changes now. Not done tests for the max buffered amount, not sure how to do it cleanly without mocking everything, or doing a it with a real client which might behave unpredictable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nearly there - just a couple of extra bits to do, comments are inline.
a93a3e6
to
3cbc4ab
Compare
Solves #144
Currently, not only do one need to push messages in parts to the datachannel, but also one needs to throttle the send function so that the datachannel buffer does not exceed
x
bytes. If x > 256kb the datachannel will close if you are using ChromeThe unit tests added are not testing what happens when the bufferedAmount exceeds maxMsgSize even though there is functionality for that.
I tested this solution in the browser-to-browser example also by sending large messages (1mb) instead of text.
Ideally, there would be a default max msg size limit would already set so that new users are not running into this when using this transport. The default behaviour is very unpredictable as it fails on different conditions depending on what browser combination used, message sizes and messaging frequency.