Ticket T1219770
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Memory leak may occur while exporting report to PDF with a Skia engine in specific Linux environments

XtraReport memory leak

created a year ago

Hi,

There appears to be a memory leak issue with XtraReports. We have two separate projects (built a little differently) that have this. When our service runs in a Docker container (Linux) and we monitor it, we see that the Working Set continually increases, until reaching a critical point after which the container stops with a "Segmentation fault (11)" and restarts automatically.

The problem does not occur when launching the application locally on Windows with Visual Studio. The Working Set remains stable at around 200 MB.

If we comment out the call to "ExportToPdfAsync(stream)" of XtraReports, the Working Set also remains stable in the container.

I have attached a sample project containing the memory leak, with a Dockerfile building a Docker image with the SDK and Microsoft monitoring tools. Simply :
- Unzip project and open command window at the project root
- dotnet build
- docker build . -t test:1
- docker run -d -p 8181:8181 -e "ASPNETCORE_URLS=http://+:8181" --name test-api test:1
- docker exec -it test-api /tools/dotnet-counters monitor -p 1
- Batch call the API on http://localhost:8181/api/v1/payStubs/report
- Observe the Working Set increasing continually
*You may have to configure DevExpress packages

Versions:
.Net Core 6
DevExpress 23.2.4

Could you please tell us if we are doing something wrong or if it's actually a bug in XtraReports ?

Thanks a lot,
Nathalie Richard

Show previous comments (8)
Vasily (DevExpress Support) a year ago

    Hello Nathalie,

    Thank you for your patience. We have thoroughly researched the case once again but we did not find any leaks related to our Reporting components. Let me share the steps we went through while diagnosing the issue:

    1. We started our research by using the steps you shared in your initial post and tested the memory usage along with your test project.

    2. We used three different memory dump collecting tools to collect memory dumps:

      • dotnet-gcdump command - to review managed memory usage.
      • dotnet-dump command - to review the complete dump.
      • GDB gcore command - to analyze unmanaged memory usage.
    3. We executed your API multiple times, and compared different dumps to analyze the memory usage.

    These are the results we obtained after researching all of the dumps:

    • Our components do not cause leaks in managed memory.
    • Our components do not cause leaks in unmanaged memory as well. The fact that the memory dump and "Working Set" counter grows does not indicate memory leaks.

    Thus, we conclude that the "Segmentation fault (11)" failure that you got in your container cannot be caused by a memory leak.

    But we found another issue that might cause this error: While testing your project on our side we found that the .NET Core threading code calls the pthread_getspecific function of the libc library, and this function crashes after a large number of calls. As a result, .NET fails to get handles for new threads, which may cause a crash. Since this crash occurs in Microsoft code, we cannot diagnose the issue further.

    The reason why this crash may occur while you use our ExportToPdfAsync method may be the fact that our Async method implementation starts several threads to run an operation asynchronously. And .NET thread creation code may fail while creating new threads, as per our research.

    Since the same code works correctly on Windows, we assume that this may be a bug in the .NET Core implementation for Linux OS. The only recommendation that we can give to work around the issue is to try replacing the ExportToPdfAsync method in your API with the synchronous ExportToPdf implementation, which should not trigger new threads. Please try this, and let us know if this resolves the initial issue in your container.

    N N
    Nathalie Richard LGI 10 months ago

      Hi Vasily,

      I'm very grateful for your deep investigation. It's much appreciated.

      I understand that it could be on Microsoft side, and particularly in the asynchronous handling. Unfortunately, I tried to use ExportToPdf instead of ExportToPdfAsync, but I have pretty much the same result.

      What surprises/confuses me in that issue is that it means everyone running XtraReport (at least ExportToPdf) on Linux would have this problem. So I can't be the only one to have reported this problem to you ?

      I found an example on GitHub from what looks to be an official (?) DevExpress examples compilation (https://github.com/DevExpress-Examples/reporting-asp-net-core-print-without-preview) using ExportToPdfAsync. I modified it a little to add theForceSkia, remove HTTPS requirement and use ExportToPdf (instead of ExportToPdfAsync), but I end up with the same unmanaged memory increasing issue until there is nothing left and the container fails.

      Don't you have a working solution on Linux ? Is it that XtraReport (or again, at least ExportToPdf) never worked on that OS ?

      Thank you

      Vasily (DevExpress Support) 10 months ago

        Hello Nathalie,

        Thank you for sharing your findings with us. I need some additional time to check this and discuss with the team. We will update this thread once we have any update.

        Answers approved by DevExpress Support

        created 10 months ago

        Hello Nathalie,

        Thank you for your patience. While conducting deep research of the memory usage on our side, we confirmed the fact that there is a memory leak in the application's unmanaged memory when a report is exported to PDF. So, your assumptions that this is not related to the Async method are absolutely correct.

        We decided to extract this issue to a separate public thread to make it available for others who may encounter this issue: Memory leak may occur while exporting report to PDF with a Skia engine in specific Linux environments. We will post further updates on this issue to that thread once we have made any progress in our research.

          Comments (1)
          Vasily (DevExpress Support) 9 months ago

            Hello Nathalie,

            I just wanted to note that our developer team has published a fix for this issue. You can request a hotfix in the Memory leak may occur while exporting report to PDF with a Skia engine in specific Linux environments thread to test this fix on your side or wait for our next minor build that will include this fix (24.1.4).

            Regarding the issue itself, it was caused by a third-party library that we used to manage fonts in the Linux environment - it did not release these fonts correctly, which caused a leak. So, to resolve the issue, we refactored the code that works with fonts and changed the way fonts are used. With this fix, you should also observe a report generation performance boost. Unfortunately, due to number of changes we made to our code base with this fix, we can only include it in our newest major build (24.1). We appreciate your understanding.

            Feel free to update this thread if you have further questions related to this topic. We will be happy to help you.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.