webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

Detach doesn't work as expected

Open lherman-cs opened this issue 5 years ago • 1 comments

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:

  1. Block the Write operation to wait until the packet to be sent.
  2. Add "flushing" to the Close operation.

lherman-cs avatar Nov 02 '19 04:11 lherman-cs

It seems to be related to this issue, https://github.com/pion/sctp/issues/77

lherman-cs avatar Nov 02 '19 16:11 lherman-cs