sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.42k stars 431 forks source link

SendTurnCreatePermissionsRequest causes program to crash #1051

Closed Hu-Said closed 7 months ago

Hu-Said commented 7 months ago

new RTCPeerConnection will cause the program to crash, The error stack is as follows:

System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') at System.Text.Encoding.GetBytes(String s) at SIPSorcery.Net.RtpIceChannel.SendTurnCreatePermissionsRequest(String transactionID, IceServer iceServer, IPEndPoint peerEndPoint) at SIPSorcery.Net.RtpIceChannel.RefreshTurn(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) at System.Threading.TimerQueue.FireNextTimers()

I'm wondering if I can monitor this kind of error and expose it in the onerror event to avoid this problem causing the program to crash!

Hu-Said commented 7 months ago

There is also a bug that causes a crash

Org.BouncyCastle.Crypto.Tls.TlsFatalAlert: internalerror(80) ---> System.InvalidOperationException: GCM cipher cannot be reused for encryption at Org.BouncyCastle.Crypto.Modes.GcmBlockCipher.CheckStatus() in //crypto/src/crypto/modes/GCMBlockCipher.cs:line 641 at Org.BouncyCastle.Crypto.Modes.GcmBlockCipher.ProcessBytes(Byte[] input, Int32 inOff, Int32 len, Byte[] output, Int32 outOff) in //crypto/src/crypto/modes/GCMBlockCipher.cs:line 330 at Org.BouncyCastle.Crypto.Tls.TlsAeadCipher.EncodePlaintext(Int64 seqNo, Byte type, Byte[] plaintext, Int32 offset, Int32 len) in //crypto/src/crypto/tls/TlsAeadCipher.cs:line 163 --- End of inner exception stack trace --- at Org.BouncyCastle.Crypto.Tls.DtlsTransport.Send(Byte[] buf, Int32 off, Int32 len) in /_/crypto/src/crypto/tls/DtlsTransport.cs:line 123 at SIPSorcery.Net.RTCSctpTransport.Send(String associationID, Byte[] buffer, Int32 offset, Int32 length) at SIPSorcery.Net.SctpAssociation.SendChunk(SctpChunk chunk) at SIPSorcery.Net.SctpDataSender.DoSend(Object state) at System.Threading.Thread.StartHelper.Callback(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

sipsorcery commented 7 months ago

For me to be of any assistance you'll need to post some log messages and steps to reproduce.

Hu-Said commented 7 months ago

For me to be of any assistance you'll need to post some log messages and steps to reproduce.

new RTCPeerConnection will cause the program to crash, The error stack is as follows:

System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') at System.Text.Encoding.GetBytes(String s) at SIPSorcery.Net.RtpIceChannel.SendTurnCreatePermissionsRequest(String transactionID, IceServer iceServer, IPEndPoint peerEndPoint) at SIPSorcery.Net.RtpIceChannel.RefreshTurn(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) at System.Threading.TimerQueue.FireNextTimers()

I'm wondering if I can monitor this kind of error and expose it in the onerror event to avoid this problem causing the program to crash!

The premise of this error is that in relay mode, when new RTCPeerConnection is used, I found the location of the error code in the source code. Adding try catch can solve the crash problem. Otherwise, the exception cannot be caught normally in the application, which will cause Crash, the following is the source code: image

sipsorcery commented 7 months ago

https://github.com/sipsorcery-org/sipsorcery/commit/e5edf3db43cf98aae95543cd3b205266f181ab9e