webrtc
webrtc copied to clipboard
Detach doesn't work as expected
Your environment.
- Version: v2.1.6
- Browser: N/A (pure go)
- Other Information - stacktraces, related issues, suggestions how to fix, links for us to have context
What did you do?
Note: p.Connect()
is simply an abstraction over pion/webrtc with its detached data channel that will do signaling, etc. Basically, writer = datachannel.ReadWriteCloser
(https://godoc.org/github.com/pion/webrtc#DataChannel.Detach)
...
writer, err := p.Connect()
if err != nil {
return err
}
defer writer.Close()
io.Copy(writer, a.DataInput)
...
What did you expect?
I would expect that writer
would block until all data has been sent from a.DataInput
.
What happened?
io.Copy
immediately finished without an error, very likely EOF. And, the other peer was still reading the data.
Appendix
I saw that Write
operation is implemented using stream.WriteSCTP
from sctp
package (https://github.com/pion/sctp/blob/master/stream.go#L148), which essentially uses its association
to queue the packet (https://github.com/pion/sctp/blob/4c68ba57a7287e324693b9cd5a20ffd3e14df287/association.go#L1818).
However, since sendPayloadData
doesn't wait for the packet to be sent, Write
operation will finish immediately.
So, just spitting out my thoughts, can we either:
- Block the
Write
operation to wait until the packet to be sent. - Add "flushing" to the
Close
operation.
It seems to be related to this issue, https://github.com/pion/sctp/issues/77