Description
SocketTransceiver.ReaderBuffer goes into infinite loop when a bad request is received from client. It seems the timeout logic is flawed
Test Case - Sending a bad request
int port = server.Port; const string msg = "1"; var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientSocket.Connect("localhost", port); clientSocket.Send(Encoding.ASCII.GetBytes(msg)); clientSocket.Close();
My fix below
private void ReadBuffer(byte[] buffer, int length) { if (length == 0) return; int totalReceived = 0; int numReceived = 0; do { numReceived = channel.Receive(buffer, totalReceived, length - totalReceived, SocketFlags.None); totalReceived += numReceived; Timeout(numReceived); } while (totalReceived < length); }
Thanks
John