Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing async sockets on Windows Server 2008 R2 causes 100% CPU usage
    primarykey
    data
    text
    <p>I have a fairly generic C# socket server that uses the asynchronous methods of the socket classes - BeginAccept(), BeginReceive(), etc. This server has been working great for the last 4 years at many customer sites running Win Server 2003. Recently I installed it on a Windows Server 2008 R2 server, 64-bit. Everything looks fine until the first client connects and issues a BeginReceive() and a BeginAccept() call in the accept handler. When this happens, the CPU usage spikes to 100% and stays that way until I close the listening socket.</p> <p>Not sure that it matters, but the server is running in a virtual machine.</p> <p>Have done a lot of testing, but nothing seems to help. Using Process Explorer, I can see that two threads are spun up shortly after the BeginReceive()/BeginAccept() calls, and they are the ones that are consuming the processor. Unfortunately, I am not able to reproduce this problem on my Win7 64-bit workstation.</p> <p>I have done a lot of research, and all that I have found so far is the following two KB articles that imply that Server 2008 R2 may have an issue with the TCP/IP components, but they are only available as hot fixes: KB2465772 and KB2477730. Am reluctant to have my customer install them until I am more certain that they will fix the issue. </p> <p>Has anyone else had this problem? If so, what did you have to do to resolve this issue?</p> <p>Here is the method that I believe causes the situation:</p> <pre><code>private void AcceptCallback(IAsyncResult result) { ConnectionInfo connection = new ConnectionInfo(); try { // Finish accept. Socket listener = (Socket)result.AsyncState; connection.Socket = listener.EndAccept(result); connection.Request = new StringBuilder(256); // Start receive and a new accept. connection.Socket.BeginReceive(connection.Buffer, 0, connection.Buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), connection); _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), listener); // CPU usage spikes at 100% shortly after this... } catch (ObjectDisposedException /*ode*/) { _log.Debug("[AcceptCallback] ObjectDisposedException"); } catch (SocketException se) { connection.Socket.Close(); _log.ErrorFormat("[AcceptCallback] Socket Exception ({0}: {1} {2}", connection.ClientAddress, se.ErrorCode, se.Message); } catch (Exception ex) { connection.Socket.Close(); _log.ErrorFormat("[AcceptCallback] Exception {0}: {1}", connection.ClientAddress, ex.Message); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload