AsposePDF appears to lockup and stop processing

We are using the AsposePDF library we currently have version 24.7. We only recently updated to 24.7.
The application pulls a message from a Queue and then uses the Aspose.Pdf.Document to create a PDF.

What we are seeing is the application is processing the request till it goes to a specific part of the code and then stops. There is no error raised and the app appears to never come back. Our only resolution is to restart the app and then it works as expected. Reprocessing the same message from the queue then works without issue.

The code looks something like the code below, its simplified but I believe the relevant parts are there.
In the logs I can see the message Adding the HTML but the code never logs the message End of method.
We have only seen this happen in prod, its not repeatable, and redeploying to prod to update the version or add extra logging is a lengthy process.

I would like to know are there any know issues with 24.7 specifically with ProcessParagraphs or else where in the PDF library that has been fixed in 24.8-24.11?

I have seen some performance fixes in the release notes, but I am not sure if they are related.
Being able to get some confirmation that its known and fixed in version 24.n will help strengthen our case to udpate and deploy.


HtmlFragment html = new HtmlFragment("<body>{resultData}</body>");
_logger.LogDebug($"Adding the HTML");
page.Paragraphs.Add(html);
 
document.ProcessParagraphs();

foreach (Page p in document.Pages) {
  p.AddStamp(dateHeader);
  p.AddStamp(reportHeader);
}
var pageNumberStamp = new PageNumberStamp  {
  Background = false,
  Format = "Page # of " + document.Pages.Count,
  BottomMargin = 10,
  HorizontalAlignment = HorizontalAlignment.Center,
  StartingNumber = 1
};

pageNumberStamp.TextState.FontStyle = FontStyles.Bold;
pageNumberStamp.TextState.FontStyle = FontStyles.Italic;

foreach (var page in document.Pages) {
  page.AddStamp(pageNumberStamp);
}
_logger.LogDebug($"End of method");

@chris01

We keep adding the performance improvements as well as fixes to every monthly update of the API that is why we always recommend using the latest version of the API. Speaking of the issue you are facing, we have not come across such issue in the past and are not really sure what could be its cause. However, we suggest and recommend that you use the latest version and if issue keeps occurring, please share some steps to reproduce it e.g. sample HTML. We will test the scenario in our environment and address it accordingly.

Thanks for the response. I will discuss internally.

In the updates 24.8 - 24.11. Do any of the performance or memory fixes relate to the ProcessParagraphs function? Were there any improvements in ProcessParagraphs?

Also we call AddStamp in the block of code.
I had found some posts about ProcessParagraphs which lead me to suspect that.
However when discussing with a colleague we started looking at AddStamp which is also in the block of code that is failing.

We found this issue which sounded similar, the app stops responding when calling AddStamp. Have there been any stability or performance fixes in 24.8 - 24.11 that relate to AddStamp?

@chris01

The ProcessParagraph() method is offered by an internal API Component and like other components, we make changes to this component as well during every monthly update. At the moment, we are not really sure if the culprit is some specific PDF document or the method itself in your case. That is why we suggested you to try the latest version and if error persists, please provide a sample document so that we can try to replicate the issue in our environment and address it accordingly.

The thread reference you shared is quite old and a lot of changes/improvements have been made since then in the API.

We have tested updating to the latest version, this did not resolve the issue.

I have pulled apart our code to create a repeatable test that I can share.

The failure appears to me to be some form of timing or race condition, where sometimes (1 out of 1000 execution on average) the ProcessParagraphs method fails to return. In prod this will never return, and the app needs to be restarted to resolve.

This test code will run the same method in batches of increasing repitions. Each run should complete in less then a second, a batch of 50 takes about 30 seconds. When the failure happens you will see the in the logs the call to ProcessParagraphs never completed.

As an example we see this putput

batch 014, test 108 of 150
before ProcessParagraphs
after ProcessParagraphs
Success 014, test 108 of 150, elapsed:00:00:00.4717404
batch 014, test 109 of 150
before ProcessParagraphs
Failed 014, test 109 of 150, elapsed:00:00:30.0014755

Can you please try the code and confirm the failure? We have a currenet license, which I can provide details of privatly as needed.

        private static readonly IEnumerable<object[]> repatedTestCase =
        Enumerable.Range(0, 100)
            .Select((i) => new object[] { i.ToString("000"), (int)(Math.Ceiling((i + 1) / 5M) * 50) });

        [Test, Category(TestCategory.Performance)]
        [TestCaseSource(nameof(repatedTestCase))]
        public void CreatePdfRepeated(string caseNumber, int count = 1)
        {
            var allowedSeconds = 30;
            for (int i = 0; i < count; i++)
            {
                var start = DateTime.Now;
                Console.WriteLine($"batch {caseNumber}, test {i} of {count}");
                if (!Task.Run(CreateSamplePDF).Wait(allowedSeconds*1000))
                {
                    Console.WriteLine($"Failed {caseNumber}, test {i} of {count}, elapsed:{DateTime.Now - start}");
                    Assert.Fail($"Failed due to timeout");
                }
                Console.WriteLine($"Success {caseNumber}, test {i} of {count}, elapsed:{DateTime.Now - start}");
            }
        }

        private void CreateSamplePDF() {
            Document document = new Document();
            Page page = document.Pages.Add();
            page.PageInfo.Margin.Left = 40;
            page.PageInfo.Margin.Right = 40;
            page.PageInfo.Margin.Top = 40;
            page.PageInfo.Margin.Bottom = 40;

            var resultData = "<span style='text-decoration: underline; color: LightGrey'>LightGrayUnderline</span>&nbsp;&nbsp;<span style='font-weight: bold; color: DarkGray'>DarkGrayBold</span>&nbsp;&nbsp; <span style='font-weight: bold; color: LightBlue'>LightBlueBold</span> <span style='text-decoration: underline; color: LightBlue'>LightBlueUnderline</span>&nbsp;&nbsp;<span style='font-weight: bold; color: Magenta'>MagentaBold</span>&nbsp;&nbsp;<span style='font-weight: bold; color: Orchid'>LightMagentaBold</span>&nbsp;&nbsp; <span style='font-weight: bold; color: Yellow'>YellowBold</span>&nbsp;&nbsp;<span style='text-decoration: underline; color: Tomato'>LightRedUnderline</span>&nbsp;&nbsp;&nbsp;&nbsp;<span style='text-decoration: underline; color: Green'>GreenUnderline</span>&nbsp;&nbsp; Loasdf <span style='font-weight: bold; color: Blue'> BoldBlue </span> <span style='font-weight: bold; color: Black'>BoldBlack</span> <span style='text-decoration: underline; color: Black'>UnderlineBlack</span><br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lo<br>rem <br>ips<br>um <br>do<br>lor si<br>t a<br>met,<br> co<br>ns<br>ec<br>tetu<br>r ad<br>ip<br>isc<br>ing elit, <br>sed do eiusmod tempor <br>incididunt ut labore et dolore <br>magna aliqua. Ut <br>enim ad minim veniam, quis n<br>ostrud exercitation <br>ullamco lab<br>oris n<br>isi ut aliqui<br>p ex ea co<br>mmodo conseq<br>uat. Duis<br> aute<br> iru<br>re dolor <br>in repre<br>henderit in<br> voluptate <br>velit e<br>sse <br>cil<br>lum<br> do<br>lor<br>e e<br>u f<br>ugia<br>t nul<br>la p<br>ariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

            HtmlFragment html = new HtmlFragment($"<body style='font-family: Consolas; font-size: 10pt;' >{resultData}</body>");
            page.Paragraphs.Add(html);

            Console.WriteLine($"before ProcessParagraphs");
            document.ProcessParagraphs();
            Console.WriteLine($"after ProcessParagraphs");

            MemoryStream pdfStream = new MemoryStream();
            document.Save(pdfStream, SaveFormat.Pdf);
        }

@chris01

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-58840

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like