Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkReply readyRead is not called, memory filling to max until crash
Forum Updated to NodeBB v4.3 + New Features

QNetworkReply readyRead is not called, memory filling to max until crash

Scheduled Pinned Locked Moved Solved General and Desktop
37 Posts 9 Posters 9.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jsulmJ jsulm

    @ankou29666 Sorry, I replied to you by mistake.

    R Offline
    R Offline
    robsparrow
    wrote on last edited by
    #21

    Solved!
    reply->setReadBufferSize(4096) did help, now readyRead signal is called and I can read data and release it from memory.

    If here is anyone with power to do something with documentation then probably here https://doc.qt.io/qt-6/qnetworkreply.html#details should be added that readyRead event is directly controlled by setReadBufferSize(), because now documentation just says "Whenever more data is received from the network and processed, the readyRead() signal is emitted."

    Also readyRead is not working as expected if we follow to this part of documentation - https://doc.qt.io/qt-6/qnetworkreply.html#setReadBufferSize
    "Setting the buffer size to 0 will make the buffer unlimited in size." as default value is 0. I would not expect even 1 signal for readyRead, but I was getting from 1-7 signals even in first seconds while file downloading until memory was filled or app was not responsive. but file was not fully downloaded while those signals was sent. So why there is such random behaviour on this signal..

    Christian EhrlicherC 1 Reply Last reply
    0
    • R robsparrow has marked this topic as solved on
    • R robsparrow

      Solved!
      reply->setReadBufferSize(4096) did help, now readyRead signal is called and I can read data and release it from memory.

      If here is anyone with power to do something with documentation then probably here https://doc.qt.io/qt-6/qnetworkreply.html#details should be added that readyRead event is directly controlled by setReadBufferSize(), because now documentation just says "Whenever more data is received from the network and processed, the readyRead() signal is emitted."

      Also readyRead is not working as expected if we follow to this part of documentation - https://doc.qt.io/qt-6/qnetworkreply.html#setReadBufferSize
      "Setting the buffer size to 0 will make the buffer unlimited in size." as default value is 0. I would not expect even 1 signal for readyRead, but I was getting from 1-7 signals even in first seconds while file downloading until memory was filled or app was not responsive. but file was not fully downloaded while those signals was sent. So why there is such random behaviour on this signal..

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #22

      @robsparrow said in QNetworkReply readyRead is not called, memory filling to max until crash:

      So why there is such random behaviour on this signal..

      There is no random behavior on this signal:

      "This signal is emitted once every time new data is available for reading from the device's current read channel. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device."

      Nothing about buffer sizes here

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      ? 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @robsparrow said in QNetworkReply readyRead is not called, memory filling to max until crash:

        So why there is such random behaviour on this signal..

        There is no random behavior on this signal:

        "This signal is emitted once every time new data is available for reading from the device's current read channel. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device."

        Nothing about buffer sizes here

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #23

        @Christian-Ehrlicher said in QNetworkReply readyRead is not called, memory filling to max until crash:

        Nothing about buffer sizes here

        I think it might. When downloading short files, the signal will only be sent once the request is totally complete. I don't know how it works in internal but I wouldn't be surprised that readyRead signal would be fired only once the bytecount in the buffer matches the bytecount declared in the reply's http header.

        I don't know if I'm right or wrong, but in that case it would explain why he never received the readyRead signal if he gets a memory overflow before the file is completely downloaded.

        Christian EhrlicherC 1 Reply Last reply
        0
        • ? A Former User

          @Christian-Ehrlicher said in QNetworkReply readyRead is not called, memory filling to max until crash:

          Nothing about buffer sizes here

          I think it might. When downloading short files, the signal will only be sent once the request is totally complete. I don't know how it works in internal but I wouldn't be surprised that readyRead signal would be fired only once the bytecount in the buffer matches the bytecount declared in the reply's http header.

          I don't know if I'm right or wrong, but in that case it would explain why he never received the readyRead signal if he gets a memory overflow before the file is completely downloaded.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #24

          @ankou29666 said in QNetworkReply readyRead is not called, memory filling to max until crash:

          I think it might. When downloading short files, the signal will only be sent once the request is totally complete. I don't know how it works in internal but I wouldn't be surprised that readyRead signal would be fired only once the bytecount in the buffer matches the bytecount declared in the reply's http header.

          No - it's clearly written: "This signal is emitted once every time new data is available for reading from the device's read channel"

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          ? 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @ankou29666 said in QNetworkReply readyRead is not called, memory filling to max until crash:

            I think it might. When downloading short files, the signal will only be sent once the request is totally complete. I don't know how it works in internal but I wouldn't be surprised that readyRead signal would be fired only once the bytecount in the buffer matches the bytecount declared in the reply's http header.

            No - it's clearly written: "This signal is emitted once every time new data is available for reading from the device's read channel"

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by A Former User
            #25

            @Christian-Ehrlicher this statement is obviously wrong.

            by the way what do they actually mean by "new data" ? and same about "availability".

            Christian EhrlicherC JonBJ 2 Replies Last reply
            0
            • ? A Former User

              @Christian-Ehrlicher this statement is obviously wrong.

              by the way what do they actually mean by "new data" ? and same about "availability".

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #26

              @ankou29666 said in QNetworkReply readyRead is not called, memory filling to max until crash:

              this statement is obviously wrong.

              Ok, no need to discuss further here...

              Qt waits for an event from the OS and emits a queued signal readyRead() so it depends on the current OS + CPU usage...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              C 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @ankou29666 said in QNetworkReply readyRead is not called, memory filling to max until crash:

                this statement is obviously wrong.

                Ok, no need to discuss further here...

                Qt waits for an event from the OS and emits a queued signal readyRead() so it depends on the current OS + CPU usage...

                C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #27

                The OP's unmodified code, on my machine with just 16GB of RAM: retrieving a local file:

                $ curl -I http://localhost/backup-2022.tar.gz
                HTTP/1.1 200 OK
                Server: nginx/1.18.0 (Ubuntu)
                Date: Tue, 28 Feb 2023 07:53:57 GMT
                Content-Type: application/octet-stream
                Content-Length: 15072231424
                Last-Modified: Tue, 28 Feb 2023 07:42:03 GMT
                Connection: keep-alive
                ETag: "63fdb04b-382600000"
                Accept-Ranges: bytes
                
                • Emits readyRead thousands of times, reads, and discards the data as expected and documented.
                • Finishes cleanly
                • Barely cracks 1% of RAM used
                • Linux Qt 6.4.2 and 5.15.2

                Exhausting RAM without completing is environmental, a Windows platform issue, or web server oddity (is it CPU bound for example).

                The only time I had a lone readyRead() call was the web server returning an HTTP 403 (PEBKAC).

                Initially, downloading multiple times in the same run consumed an extra memory chunk each time because the QNetworkReply is not deleted. Fixing that fixes this growth.

                1 Reply Last reply
                2
                • ? A Former User

                  @Christian-Ehrlicher this statement is obviously wrong.

                  by the way what do they actually mean by "new data" ? and same about "availability".

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #28

                  @robsparrow
                  The results shown by @ChrisW67 under Linux are indeed what would be expected.

                  One thing to check: your earlier Memory usage screenshot from Task Manager > Performance looks like it's showing for whole machine? Can you verify whether that memory is being used by your Qt process versus whether it is attributed to something else, like the OS itself?

                  ? 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @robsparrow
                    The results shown by @ChrisW67 under Linux are indeed what would be expected.

                    One thing to check: your earlier Memory usage screenshot from Task Manager > Performance looks like it's showing for whole machine? Can you verify whether that memory is being used by your Qt process versus whether it is attributed to something else, like the OS itself?

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #29

                    @JonB that wasn't my graphs !!! All I said is I was wondering what the behavior is for big files. Personally I'm not concerned by such file sizes, and haven't yet reached the point where I will have to deal with bigger file sizes (and I'll still be well below RAM quantity anyways).

                    I have already seen inaccurate documentations ;) so sometimes I take them a little cautiously.

                    JonBJ 1 Reply Last reply
                    0
                    • ? A Former User

                      @JonB that wasn't my graphs !!! All I said is I was wondering what the behavior is for big files. Personally I'm not concerned by such file sizes, and haven't yet reached the point where I will have to deal with bigger file sizes (and I'll still be well below RAM quantity anyways).

                      I have already seen inaccurate documentations ;) so sometimes I take them a little cautiously.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #30

                      @ankou29666 My fault, I meant to address that to the OP @robsparrow, corrected.

                      J.HilkJ 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @ankou29666 My fault, I meant to address that to the OP @robsparrow, corrected.

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #31

                        @JonB its the new forum style at fault here,

                        @ankou29666 and @robsparrow have the same color back ground image.

                        It's also the only thing I tend to look at, at first glance at least


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        JonBJ 1 Reply Last reply
                        0
                        • J.HilkJ J.Hilk

                          @JonB its the new forum style at fault here,

                          @ankou29666 and @robsparrow have the same color back ground image.

                          It's also the only thing I tend to look at, at first glance at least

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #32

                          @J-Hilk
                          I also find the new behaviour here when typing @... since the forum update confusing.... Though it's probably not to blame for my fault above :)

                          J.HilkJ 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @J-Hilk
                            I also find the new behaviour here when typing @... since the forum update confusing.... Though it's probably not to blame for my fault above :)

                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #33

                            @JonB In think that got reverted!


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            JonBJ 1 Reply Last reply
                            0
                            • J.HilkJ J.Hilk

                              @JonB In think that got reverted!

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #34

                              @J-Hilk
                              Umm, nope, try typing just @ versus @ followed by something. And it seems to behave differently inside a post, at least when I come back to edit one I have already made.... However this is now OT in this unsolved thread....

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                robsparrow
                                wrote on last edited by
                                #35

                                Windows 10 Build 19044. CPU - Ryzen 9 4900H.

                                Tests:

                                1. without "setReadBufferSize()" - each app rerun gives different count of readyRead signals until app starts filling memory until crash - usually 0-3 signals in first 2-5 seconds and then its not responding anymore and memory is filled until crash
                                2. with reply->setReadBufferSize(1024); - readyRead is called many times per second, memory is not filled, everything is fine

                                Its not making any load on CPU even in test case (1) when memory is filled.

                                ? JoeCFDJ 2 Replies Last reply
                                0
                                • R robsparrow

                                  Windows 10 Build 19044. CPU - Ryzen 9 4900H.

                                  Tests:

                                  1. without "setReadBufferSize()" - each app rerun gives different count of readyRead signals until app starts filling memory until crash - usually 0-3 signals in first 2-5 seconds and then its not responding anymore and memory is filled until crash
                                  2. with reply->setReadBufferSize(1024); - readyRead is called many times per second, memory is not filled, everything is fine

                                  Its not making any load on CPU even in test case (1) when memory is filled.

                                  ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on last edited by
                                  #36

                                  @JonB said in QNetworkReply readyRead is not called, memory filling to max until crash:

                                  @ankou29666 My fault, I meant to address that to the OP @robsparrow, corrected.

                                  no worry, not the first time this happens in this topic (but as this topic is tagged as solved, i think I can reasonably hope this is the last !!!)

                                  @robsparrow said in QNetworkReply readyRead is not called, memory filling to max until crash:

                                  Windows 10 Build 19044. CPU - Ryzen 9 4900H.

                                  Tests:

                                  1. without "setReadBufferSize()" - each app rerun gives different count of readyRead signals until app starts filling memory until crash - usually 0-3 signals in first 2-5 seconds and then its not responding anymore and memory is filled until crash
                                  2. with reply->setReadBufferSize(1024); - readyRead is called many times per second, memory is not filled, everything is fine

                                  Its not making any load on CPU even in test case (1) when memory is filled.

                                  thanks for the share, that's good to know

                                  1 Reply Last reply
                                  0
                                  • R robsparrow

                                    Windows 10 Build 19044. CPU - Ryzen 9 4900H.

                                    Tests:

                                    1. without "setReadBufferSize()" - each app rerun gives different count of readyRead signals until app starts filling memory until crash - usually 0-3 signals in first 2-5 seconds and then its not responding anymore and memory is filled until crash
                                    2. with reply->setReadBufferSize(1024); - readyRead is called many times per second, memory is not filled, everything is fine

                                    Its not making any load on CPU even in test case (1) when memory is filled.

                                    JoeCFDJ Offline
                                    JoeCFDJ Offline
                                    JoeCFD
                                    wrote on last edited by
                                    #37

                                    @robsparrow has the buffer size to be 1024? Have you tried any other numbers for comparison?

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved