You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "John Cai (JIRA)" <ji...@apache.org> on 2015/06/02 23:21:49 UTC

[jira] [Created] (AVRO-1675) CSharp SocketTransceiver.ReadBuffer goes into infinite loop

John Cai created AVRO-1675:
------------------------------

             Summary: CSharp SocketTransceiver.ReadBuffer goes into infinite loop
                 Key: AVRO-1675
                 URL: https://issues.apache.org/jira/browse/AVRO-1675
             Project: Avro
          Issue Type: Bug
          Components: csharp
    Affects Versions: 1.7.7
            Reporter: John Cai


SocketTransceiver.ReaderBuffer goes into infinite loop when a bad request is received from client.  It seems the timeout doesn't flawed

Test Case - Sending a bad request
{noformat}
            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();   
{noformat}

My fix below

{noformat}
 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);
        }
{noformat}

Thanks

John



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)