https://bugzilla.novell.com/show_bug.cgi?id=644936
https://bugzilla.novell.com/show_bug.cgi?id=644936#c0 Summary: NetworkStream.Read() block and use 100% CPU if the socket has been shutted down Classification: Mono Product: Mono: Class Libraries Version: 2.6.x Platform: Other OS/Version: Other Status: NEW Severity: Major Priority: P5 - None Component: CORLIB AssignedTo: [email protected] ReportedBy: [email protected] QAContact: [email protected] Found By: --- Blocker: --- User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.5 I was trying to use the memcache http://sourceforge.net/projects/memcacheddotnet/ C# lib... and if i restart the memcached server i saw that the program blocked and use 100% CPU. This problem doesn't happens on Windows (MS.NET) I've isolated the problem and made a test case: Reproducible: Always Steps to Reproduce: 1.Install Memcached on a server 2.run socketTest public static void socketTest () { Socket sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Connect (new IPEndPoint (IPAddress.Parse ("10.69.207.44"), 11211)); NetworkStream _networkStream = new NetworkStream (sock); for (;;) { Console.WriteLine (sock.Connected); string cmd = "get mykey\n"; byte[] cmdByte = System.Text.ASCIIEncoding.ASCII.GetBytes (cmd); _networkStream.Write (cmdByte, 0, cmdByte.Length); _networkStream.Flush(); byte[] b = new byte[1]; MemoryStream memoryStream = new MemoryStream (); bool eol = false; while (_networkStream.Read (b, 0, 1) != -1) { if (b[0] == 13) { eol = true; } else { if (eol) { if (b[0] == 10) break; eol = false; } } // cast byte into char array memoryStream.Write (b, 0, 1); } string temp = UTF8Encoding.UTF8.GetString (memoryStream.GetBuffer ()).TrimEnd ('\0', '\r', '\n'); Console.WriteLine (temp); Console.ReadLine (); } } 3. This programs send a command to the memcached server and read the output.. and loop! 4. Stop the memcached server... and you'll see that the program would block at : _networkStream.Read (b, 0, 1) Actual Results: The program blocks : with the thread dump : "<unnamed thread>" tid=0x0x2b3bfcb7f600 this=0x0x2aaaaacdce60 thread handle 0x405 state : not waiting owns () at (wrapper managed-to-native) System.Net.Sockets.Socket.Receive_internal (intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&) <IL 0x00014, 0x0006b> at (wrapper managed-to-native) System.Net.Sockets.Socket.Receive_internal (intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&) <IL 0x00014, 0x0006b> at System.Net.Sockets.Socket.Receive_nochecks (byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.Sockets.SocketError&) [0x00000] in /home/hfongarnand/mono/monostablegit/mono/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:615 at System.Net.Sockets.Socket.Receive (byte[],int,int,System.Net.Sockets.SocketFlags) [0x00070] in /home/hfongarnand/mono/monostablegit/mono/mcs/class/System/System.Net.Sockets/Socket.cs:2398 at System.Net.Sockets.NetworkStream.Read (byte[],int,int) [0x0004f] in /home/hfongarnand/mono/monostablegit/mono/mcs/class/System/System.Net.Sockets/NetworkStream.cs:363 at MemCachedTest.MainClass.socketTest () [0x000ac] in /home/hfongarnand/Projects/MemCached/MemCachedTest/Main.cs:63 at MemCachedTest.MainClass.Main (string[]) [0x00000] in /home/hfongarnand/Projects/MemCached/MemCachedTest/Main.cs:17 at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x0001d, 0x00054> Expected Results: The program should stop with a proper exception : Exception non gérée : System.IO.IOException: Impossible de lire les données de l a connexion de transport. ---> System.Net.Sockets.SocketException: Une connexion établie a été abandonnée par un logiciel de votre ordinateur hôte at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s ize) --- Fin de la trace de la pile d'exception interne --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s ize) at MemCachedTest.MainClass.socketTest() at MemCachedTest.MainClass.Main(String[] args) as in windows... It's blocking us for using MemCache on our web servers... -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. You are the assignee for the bug. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
