diff --git a/sctptransport.go b/sctptransport.go index 7af054f3a25..5ea2df952f7 100644 --- a/sctptransport.go +++ b/sctptransport.go @@ -238,7 +238,9 @@ ACCEPT: }, r, r.api.settingEngine.LoggerFactory.NewLogger("ortc")) if err != nil { // This data channel is invalid. Close it an log an error. - dc.Close() + if err := dc.Close(); err != nil { + r.log.Errorf("Failed to close invalid data channel: %v", err) + } r.log.Errorf("Failed to accept data channel: %v", err) r.onError(err) // We've received a datachannel with invalid configuration. We can still receive other datachannels. diff --git a/sctptransport_test.go b/sctptransport_test.go index cb5371f5ae0..2f97bcd569f 100644 --- a/sctptransport_test.go +++ b/sctptransport_test.go @@ -67,8 +67,10 @@ func TestSCTPTransportOnClose(t *testing.T) { require.NoError(t, err) answerPC.OnDataChannel(func(dc *DataChannel) { - dc.OnMessage(func(msg DataChannelMessage) { - dc.Send([]byte("hello")) + dc.OnMessage(func(_ DataChannelMessage) { + if err := dc.Send([]byte("hello")); err != nil { + t.Error("failed to send message") + } }) }) @@ -91,7 +93,9 @@ func TestSCTPTransportOnClose(t *testing.T) { recvMsg <- struct{}{} }) dc.OnOpen(func() { - dc.Send([]byte("hello")) + if err := dc.Send([]byte("hello")); err != nil { + t.Error("failed to send initial msg", err) + } }) } }) @@ -111,7 +115,8 @@ func TestSCTPTransportOnClose(t *testing.T) { ch <- err }) - offerPC.Close() // This will trigger sctp onclose callback on remote + err = offerPC.Close() // This will trigger sctp onclose callback on remote + require.NoError(t, err) select { case <-ch: