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> <span style='font-weight: bold; color: DarkGray'>DarkGrayBold</span> <span style='font-weight: bold; color: LightBlue'>LightBlueBold</span> <span style='text-decoration: underline; color: LightBlue'>LightBlueUnderline</span> <span style='font-weight: bold; color: Magenta'>MagentaBold</span> <span style='font-weight: bold; color: Orchid'>LightMagentaBold</span> <span style='font-weight: bold; color: Yellow'>YellowBold</span> <span style='text-decoration: underline; color: Tomato'>LightRedUnderline</span> <span style='text-decoration: underline; color: Green'>GreenUnderline</span> 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);
}