Connecting, disconnecting, connecting etc. makes the lib hang/crash

Topics: Admin Tool, Developers
Feb 6, 2012 at 3:35 PM

After Connecting and disconnecting and connecting and disconnecting ... I get this error:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object  at System.Net.Sockets.TcpClient.get_Connected () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.Sockets/TcpClient.cs:128   at System.Net.Battlefield3.RconClientBase.get_IsConnected () [0x00000] in /Users/rj/Dropbox/MonoDevelop/Projects/Mojo/GamezAdmin/BF3RCon/BF3RCon/RconClientBase.cs:100   at (wrapper remoting-invoke-with-check) System.Net.Battlefield3.RconClientBase:get_IsConnected ()  at System.Net.Battlefield3.RconClient.ReceiveCallback (IAsyncResult ar) [0x00013] in /Users/rj/Dropbox/MonoDevelop/Projects/Mojo/GamezAdmin/BF3RCon/BF3RCon/RconClient.cs:637 

I also experience that the connect can stall if connecting, disconnecting, connecting etc.

Can you please try connecting, disconnecting, connecting etc. and see if you can force the library to hang/stall?





Feb 6, 2012 at 11:55 PM

It looks like this is a bug by Mono, judging by the stacktrace. After looking at the source code of Mono, TcpClient.Connected simply returns client.Connect, where client is a Socket; this will obviously fail if the Socket is null, like in that exception. I'm not sure if this is the same behavior in .NET, because I'm not at my regular computer to check (or put out a fix right now, but at least you're sleeping).

However, whether or not this problem exists only in Mono doesn't matter, since this library is supposed to be Mono-compatible. Since you're awake before me, if you need it fixed immediately, you can just catch the NullReferenceException in RconClientBase.IsConnected, since that'll end up being my fix.

Feb 7, 2012 at 4:19 PM

Perfect - I will test it :) Thanks!!