Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1675

CSharp SocketTransceiver.ReadBuffer goes into infinite loop

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 1.7.7
    • None
    • csharp

    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

      Attachments

        1. AVRO-1675.patch
          1.0 kB
          John Cai

        Activity

          People

            Unassigned Unassigned
            johncai1 John Cai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: