Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85872

QTcpSocket High Bandwidth Reading Loses Packets



    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Incomplete
    • Affects Version/s: 5.15.0 RC2
    • Fix Version/s: None
    • Component/s: Network: Sockets
    • Labels:
    • Environment:
      MacOS 10.13, Intel i5
    • Platform/s:


      Reading at a high frequency from a QTcpSocket causes the read information to skip bytes. This omission of bytes in invalid behavior under the TCP protocol. 

      Comparing the incoming data to the QTcpSocket as seen through Wireshark and the data read from the QTcpSocket into a buffer, there is a mismatch. Reading from the socket under high load will output into an incomplete set of bytes (skipped portions).

      According to the TCP protocol guarantees, bytes should be received in full and in order, so I'm not sure what is going on. 



      The relevant code can be found here and the focus is the `SocketRead()` function: 


      The specific application of this use case requires extremely fast reads from the QTcpSocket, pretty much as fast as I can receive data. Because of issues using the `ReadyRead` signal, I have opted to use the `waitForReadyRead()` since I can poll at a greater rate and get a smoother data flow. 


      Data in this case is encoded into frames, or set numbers of bytes that I am receiving. Each time that I read any number of bytes I decrement the number of bytes from the frame left to receive. I can tell I am missing bytes by the fact that when I send a test pattern of a constant frame, I am getting holes in the pattern, where bytes never appeared. I have validated this discovery by looking directly at the memory trace of the read buffer and writing code to check for mismatches in this test pattern. 

      I've included a screenshot of what this test pattern looks like just so you can see. 


      I'm happy to provide more details. 



      The attached image represents a memory trace of the mismatch in data. The values should count upwards in order. Looking at the image, it is evident that there is a section missing which makes it appear as if there are several sections of bytes missing. 



        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            tpochep Timur Pocheptsov
            shuson Scott Huson
            0 Vote for this issue
            4 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes