Not logged in. · Lost password · Register
Forum: MatriX RSS
Page:  1  2  next
Avatar
rodja #1
Member since Feb 2016 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: Xamarin iOS disconnections
Hi,

I've been having a lot of disconnections with production users.
I was able to get the socket exception from those users. Maybe you can help me just understand what we could do on the client side to avoid those issues?

Here's the list:

1) I'm handling this one by deleting and reopening the matrix client.
System.ObjectDisposedExceptionCannot access a disposed object. Object name: 'System.Net.Sockets.Socket'.
System.Net.Sockets.Socket.ThrowIfDisposedAndClosed()
System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult, ref SocketError errorCode)
System.Net.Sockets.Socket.EndSend(IAsyncResult result)
System.Net.Sockets.NetworkStream.EndWrite(IAsyncResult ar)

2) Sometimes the connection closes and we only get the error (using all event handlers for errors) after the user try to send a chat message (or presence)
Matrix.XmppStreamExceptionUnable to send data. The XMPP Stream is inactive

3) I'm verifying if what I'm sending is null before sending. Still I'm getting this:
System.NullReferenceExceptionObject reference not set to an instance of an object
Raw
Matrix.Net.ClientSocket.Send(byte[] bData)

4) Another one that is kinda like the 1st. Handling by reconnecting.
Matrix.Net.SynchronousConnectExceptionClientSocket Connection request failed.
System.ObjectDisposedExceptionCannot access a disposed object. Object name: 'System.Net.Sockets.Socket'.
System.Net.Sockets.Socket.ThrowIfDisposedAndClosed()
System.Net.Sockets.Socket.EndConnect(IAsyncResult result)
Matrix.Net.ClientSocket.EndConnect(IAsyncResult ar)

5) Really don't know why this happens to some users only, handling by reconnecting:
System.IO.IOExceptionThe authentication or decryption has failed.
Raw
Mono.Security.Protocol.Tls.SslStreamBase.EndRead(IAsyncResult asyncResult)
System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
System.Net.Security.SslStream.AuthenticateAsClient(string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Matrix.Net.ClientSocket.DoStartSecurityLayer(SslProtocols protocol)
System.IO.IOExceptionThe authentication or decryption has failed.
Mono.Security.Protocol.Tls.SslClientStream.EndNegotiateHandshake(IAsyncResult result)
Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback(IAsyncResult asyncResult)
Mono.Security.Protocol.Tls.TlsExceptionThe server stopped the handshake.
Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord(IAsyncResult ar, bool ignoreEmpty)
Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker(IAsyncResult result)
Properties & Custom Values
Alert   
Format{
  "Level": "Fatal",
  "Description": "HandshakeFailiure",
  "IsWarning": false,
  "IsCloseNotify": false,
  "getType": "Mono.Security.Protocol.Tls.Alert"
}
HResult   
-2146233088

This is the assembly info for the Matrix Library that I'm using:
  1. [assembly: AssemblyVersion("1.6.0.6")]
  2. [assembly: AssemblyDate("20150123")]
  3. [assembly: AssemblyCompany("AG-Software")]
  4. [assembly: AssemblyConfiguration("")]
  5. [assembly: AssemblyCopyright("Copyright © 2008-2015")]
  6. [assembly: AssemblyDescription("MatriX XMPP library")]
  7. [assembly: AssemblyFileVersion("1.6.0.6")]
  8. [assembly: AssemblyProduct("MatriX")]
  9. [assembly: AssemblyTitle("MatriX")]
  10. [assembly: AssemblyTrademark("")]
  11. [assembly: CompilationRelaxations(8)]
  12. [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
  13. [assembly: ComVisible(false)]
  14. [assembly: Guid("032c2743-60f9-4113-8972-9565cf3dcf21")]

I'm using the library and all the code is being called in the PCL project.

Thanks!
This post was edited on 2016-02-07, 16:55 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Rodja,

as you use the Xamarin for iOS version I assume that your users are on mobile.
Most of the Exceptions you have listed seem to be related to connection issues.

When you try to connect without having a stable internet connection you will see those errors. Also when your internet goes down while being connected.

In this case you just have to retry to connect when internet is available again.

Exception #5 can also be related to connection issues, or there is a problem with your servers TLS certificate.
This exception is coming from Mono, not from MatriX. MatriX is only calling AuthenticateAsClient to upgrade the connection as TLS.

When you application has to operate under conditions where the Internet goes down often it can make sense to destroy always the complete XmppClient object and create a complete new XmppClient on connection loss or connection errors.

You are also using an older MatriX version, so I would also suggest to update it.

Alex
Avatar
rodja #3
Member since Feb 2016 · 5 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

I'm using the latest version of Matrix for Xamarin.iOS.

After the iOS 10,SDK upgrade our app is crashing a lot because of Matrix. The crash is 100% reproducible when the user lock/unlock the device.

Here're some of the logs that I could symbolicate:

System.InvalidOperationExceptionInvalid nested call.
Raw
Mono.Net.Security.MobileAuthenticatedStream.StartOperation(ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, AsyncProtocolRequest asyncRequest, string name)MobileAuthenticatedStream.cs:373
Mono.Net.Security.MobileAuthenticatedStream.Close()MobileAuthenticatedStream.cs:742
System.IO.Stream.Dispose()stream.cs:260
System.Net.Security.SslStream.Dispose(bool disposing)SslStream.cs:346
System.IO.Stream.Close()stream.cs:248
System.IO.Stream.Dispose()stream.cs:260
Matrix.Net.ClientSocket.Disconnect()<b936e847b77f437bb288a627feb9e3dd>:0
Matrix.Net.ClientSocket.EndReceive(IAsyncResult ar)<b936e847b77f437bb288a627feb9e3dd>:0
System.Net.LazyAsyncResult.Complete(IntPtr userToken)_LazyAsyncResult.cs:415
System.Net.LazyAsyncResult.ProtectedInvokeCallback(object result, IntPtr userToken)_LazyAsyncResult.cs:368
System.Net.LazyAsyncResult.InvokeCallback(object result)_LazyAsyncResult.cs:376
Mono.Net.Security.AsyncProtocolRequest.StartOperation()AsyncProtocolRequest.cs:206
Mono.Net.Security.AsyncProtocolRequest.<StartOperation>m__0(object _)AsyncProtocolRequest.cs:193
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state)threadpool.cs:1304
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state, bool preserveSyncCtx)executioncontext.cs:957
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, object state, bool preserveSyncCtx)executioncontext.cs:904
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()threadpool.cs:1281
System.Threading.ThreadPoolWorkQueue.Dispatch()threadpool.cs:854
ObjCRuntime.Runtime.ThreadPoolDispatcher(Func<TResult> callback)Runtime.cs:238
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()threadpool.cs:1206

System.IO.IOExceptionUnable to write data to the transport connection: Cannot access a disposed object. Object name: 'System.Net.Sockets.Socket'..
Raw
System.Net.Sockets.NetworkStream.Write(byte[] buffer, int offset, int size)NetworkStream.cs:602
Mono.Net.Security.MobileAuthenticatedStream.InnerFlush()MobileAuthenticatedStream.cs:561
Mono.Net.Security.MobileAuthenticatedStream.InnerWrite()MobileAuthenticatedStream.cs:555
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(AsyncOperationStatus status)AsyncProtocolRequest.cs:267
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation()AsyncProtocolRequest.cs:218
Mono.Net.Security.AsyncProtocolRequest.StartOperation()AsyncProtocolRequest.cs:199

System.IO.IOExceptionUnable to write data to the transport connection: Cannot access a disposed object. Object name: 'System.Net.Sockets.Socket'..
Raw
System.Net.Sockets.NetworkStream.Write(byte[] buffer, int offset, int size)
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(AsyncOperationStatus status)
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation()
Mono.Net.Security.AsyncProtocolRequest.StartOperation()

And OnXMLError with a null Exception.

It's imperative for our business to be able to fix those issues asap. If I just don't call XmppClient.open() it won't crash at all.
Please let us know how to proceed on this.

Thank you.
Avatar
Alex #4
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by rodja:
After the iOS 10,SDK upgrade our app is crashing a lot because of Matrix. The crash is 100% reproducible when the user lock/unlock the device.

The stacktrace does not show where exactly an exception in MatriX occurs. Can you try to get a better stacktrace? Exact type of exception and where it should occur in MatriX?
Have you tried to Close the connection when the device gets locked?

Quote by rodja:
If I just don't call XmppClient.open() it won't crash at all.
Please let us know how to proceed on this.

I don't understand what that means, can you please elaborate?

Have you tried not to reuse the previous XmppClient instance and create a complete new XmppClient instead?

Alex
Avatar
rodja #5
Member since Feb 2016 · 5 posts
Group memberships: Members
Show profile · Link to this post
The stacktrace does not show where exactly an exception in MatriX occurs. Can you try to get a better stacktrace? Exact type of exception and where it should occur in MatriX?
It's a very weird crash. The app stays open, but it restarts. It doesn't generate any crash logs. What I sent I was able to get only by using Xamarin Insights. I'm trying to get more info out of this, but so far no luck. This is the output from the Device Log:
Info (323) Warning: Unhandled exception: System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.
Info (323) Warning: Unhandled exception: System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.
Info (323) Warning: Unhandled exception: System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.
Info (323) Warning: Unhandled exception: System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.
Info (323) Warning: Unhandled exception: System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.
Info (323) Warning: Unhandled exception: System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.

Have you tried to Close the connection when the device gets locked?
Have you tried not to reuse the previous XmppClient instance and create a complete new XmppClient instead?
Yes, I'm closing the XmppClient OnAppResign and deleting the XmppClient OnAppBackgrounded.
Here's how I'm deleting the XmppClient:
_MClient = null;
System.GC.Collect();
I have also tried to delete the client whenever the app resigned, but the crash still happens.

I don't understand what that means, can you please elaborate?
Sorry. I was trying to figure out if the crash was happening in Matrix or in anywhere else in the app. We're not using a socket anywhere else. When I don't open the connection (i.e. call XmppClient.Open()), the crash doesn't happen.
Avatar
rodja #6
Member since Feb 2016 · 5 posts
Group memberships: Members
Show profile · Link to this post
Here's a new crash that a client just experienced:

System.IO.IOExceptionclose failed
Raw
Mono.Net.Security.MobileAuthenticatedStream.StartOperation(ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, AsyncProtocolRequest asyncRequest, string name)
Mono.Net.Security.MobileAuthenticatedStream.Close()
System.IO.Stream.Dispose()
System.Net.Security.SslStream.Dispose(bool disposing)
System.IO.Stream.Close()
System.IO.Stream.Dispose()
Matrix.Net.ClientSocket.Disconnect()
Matrix.Net.ClientSocket.EndReceive(IAsyncResult ar)
System.Net.LazyAsyncResult.Complete(IntPtr userToken)
System.Net.LazyAsyncResult.ProtectedInvokeCallback(object result, IntPtr userToken)
System.Net.LazyAsyncResult.InvokeCallback(object result)
Mono.Net.Security.AsyncProtocolRequest.StartOperation()
Mono.Net.Security.AsyncProtocolRequest.<StartOperation>m__0(object _)
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state)
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, object state, bool preserveSyncCtx)
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
System.Threading.ThreadPoolWorkQueue.Dispatch()
ObjCRuntime.Runtime.ThreadPoolDispatcher(Func<TResult> callback)
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()


System.ObjectDisposedExceptionCannot access a disposed object. Object name: 'System.Net.Sockets.NetworkStream'.
System.Net.Sockets.NetworkStream.Write(byte[] buffer, int offset, int size)
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation(AsyncOperationStatus status)
Mono.Net.Security.AsyncProtocolRequest.ProcessOperation()
Mono.Net.Security.AsyncProtocolRequest.StartOperation()

That's all the info I can get
Avatar
rodja #7
Member since Feb 2016 · 5 posts
Group memberships: Members
Show profile · Link to this post
I debugged this with some extra help from Alex and we couldn't find anything in the Matrix that was causing this issue.
After hitting my head a bunch of times, we finally figure it out that the issue was in the Apple TLS.

Whenever I compiled an ran with plain Sals mechanism (on both server and client), the crash didn't happen.

For anyone else having this issue this is how I fixed:
1) Select your iOS project > Options
2) Build > iOS Build
3) SSL/TLS implementation: change from Apple TLS (default) to Mono (TLS v1.0)
Avatar
Alex #8
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
great to hear that the issue id fixed now. This is why the stacktrace starts in Mono.Net.Security
Thanks for letting us know.

Alex
Avatar
dbarbieri #9
Member since May 2017 · 7 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
I'm using Matrix.Mono plugin in a PCL library on Xamarin. I had the same problem described by rodja on iOS and I solved it in the same way, switching TLS/SSL Implementation to Mono. Unfortunately that option has been removed from new releases of Xamarin.iOS, starting from 10.8, and I cannot update Xamarin anymore.
Avatar
Alex #10
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
1) You should use MatriX.Xamarin.iOS and not Matrix.Mono
2) Have you tried to contact the Xamarin support? The exception mentioned here in this thread is bubbling up from the underlying Xamarin Mono code. There is not much be can do here.
Avatar
dbarbieri #11
Member since May 2017 · 7 posts
Group memberships: Members
Show profile · Link to this post
I'm using Matrix.Mono because I refer it from a PCL library, which is used by an iOS and an Android project. I have no problems with the Android one. From the logs, it seems you're trying to dispose an already disposed stream, and the new Apple TLS implementation doesn't appreciate. I'll try to contact Xamarin support. Anyway, isn't it possible to surround your System.IO.Stream.Dispose() call in Matrix.Net.ClientSocket.Disconnect() with a try/catch as a workaround?

Thank you in advance,
Domenico
Avatar
Alex #12
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
in Disconnect it checking for null before disposing it.

  1. if (networkStream != null)
  2.    networkStream.Dispose();

Happy to make a change when you can provide stacktraces which show the root of the problem.
The other stacktraces posted here in the thread always indicate the problem inside the Xamarin/Mono libraries.

Alex
Avatar
Alex #13
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
just pushed a new Mono Nuget with the latest updates.
We also added an additional try/catch in Disconnect for you.

Alex
Avatar
dbarbieri #14
Member since May 2017 · 7 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
thanks, it seems working now without issues.

Regards,
Domenico
Avatar
Alex #15
Member since Feb 2003 · 4296 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Great to hear.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Page:  1  2  next
Forum: MatriX RSS