Convert PDF to image (JPEF) crash from time to time

Hi,
Converting PDF to JPEG (only the first page to make a thumbnail) hang sometimes the request and ended up making the server unavailable.

I think there is a deadlock somewhere or a part is not thread safe.

I can reproduce the issue with a console sample trying to convert 5 documents simultaneously.
The issue does not occurs for every PDF files.

Attached a snapshot of our DebugDiag Analysis Report .aspose_pdf_snap.png (57.8 KB)

I cannot provide a PDF publicly reproducing the error.

The sample to reproduce :

static void Main(string[] args)
    {
        var asposeLicense = "AsposePdfBug.Aspose.Total.lic";
        var asposeLic = new License();
        asposeLic.SetLicense(asposeLicense);

        var filesFolder = @"E:\src\AsposePdfBug\AsposePdfBug\files"; // put at least 5 PDF files

        Console.WriteLine($"Convert PDF from {filesFolder}");

        var filesToConvert = Directory.GetFiles(filesFolder, "*.pdf");

        Parallel.ForEach(filesToConvert, (currentFilename) =>
        {
            try
            {
                var resultFilename = ConvertDocumentToImage(currentFilename);
                Console.WriteLine($"Image converted to {resultFilename}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error converting file {currentFilename} : {e.Message}");
                throw;
            }
        });

        Console.WriteLine("Done.");
        Console.ReadLine();
    }

    private static string ConvertDocumentToImage(string fileName)
    {
        byte[] result = null;

        using (var fs = File.OpenRead(fileName))
        {
            using (var doc = new Document(fs))
            {
                //Resolution = 150, Width = 81, Height = 115, PageIndexToConvert = 1
                var imageDevice = new JpegDevice(81, 115, new Resolution(150), 75);

                if (doc.Pages.Count < 1)
                {
                    return null;
                }

                using (var outputStream = new MemoryStream())
                {
                    imageDevice.Process(doc.Pages[1], outputStream);

                    result = outputStream.ToArray();
                }
            }
        }

        var outputFilename = Path.ChangeExtension(fileName, "jpg");
        File.WriteAllBytes(outputFilename, result);
        return outputFilename;
    }
}

I reproduce the error with Aspose.PDF 20.4.0 and .NET 4.7.2

@stratts

You may please send your sample PDF document in a private message by clicking over username and pressing Blue Message Button. We will surely test the scenario in our environment and address it accordingly.

@stratts

Thanks for sharing sample PDF document.

We have tested the scenario in our environment with Aspose.PDF for .NET 20.4 and were unable to notice any issue. We have used following code snippet and run it against 5 files including 4 from our sample files.

string[] filesToConvert = {dataDir + "file01.pdf", dataDir + "OR341.pdf", dataDir + "outputPDF.pdf", dataDir + "replaced.pdf", dataDir + "ARTICLE 1-converted.pdf" };
            System.Threading.Tasks.Parallel.ForEach(filesToConvert, (currentFilename) =>
            {
                try
                {
                    using (Document doc = new Document(currentFilename))
                    {
                        //foreach(Page page in doc.Pages)
                        //{
                        Rectangle rect = doc.Pages[1].GetPageRect(true);
                        JpegDevice jpegDevice = new JpegDevice(81, 115, new Resolution(150), 75);//new JpegDevice((int)rect.Width, (int)rect.Height, new Resolution(150), 100);
                        jpegDevice.Process(doc.Pages[1], dataDir + currentFilename.Substring(currentFilename.Length - 10) + ".jpg");
                        //}
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error converting file {currentFilename} : {e.Message}");
                    throw;
                }
            });

Would you kindly share a sample console application which is able to reproduce the issue that you are facing. We will again test it in our environment and address the issue accordingly.

Hi,

Thank you for your efforts.

I share a sample to reproduce in my first post. You have to put 5 copies of the file I provided in the filesFolder and put a valid licence.

Let me know if you need more informations or if I need to put the sample on github.

@stratts

We again tested the scenario as per your suggestions and were still unable to notice any issue. Would you please share a sample console application which can reproduce issue in any environment. We will further proceed to assist you accordingly.

Were you able to reproduce with the example I gave you? And if so, do you have any news?
Thank you

@stratts

Sorry for the delayed response.

We were able to replicate the issue with 10 copies of the sample file. Hence, have logged an investigation ticket as PDFNET-48193 in our issue tracking system. We will further look into this and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi,
Any news on when the bug will be fixed?
Thanks

@stratts

The issue was logged under free support model and will be investigated/resolved on first come first serve basis. We really regret to inform you that investigation against the issue has not been made yet and we are not in a position to share some reliable ETA. However, we will surely inform you as soon as we have some certain news about issue fix. Please give us some time.

We apologize for the inconvenience caused.

Hello,
The issue is still not fixed.
Now we have paid support, would it be possible to speed things up?
Thank you.

@stratts

Yes, sure. If you have subscription of paid support, you can surely escalate things by creating a post in paid support forum including reference of the ticket ID. Your issue will be escalated accordingly.

The issues you have found earlier (filed as PDFNET-48193) have been fixed in Aspose.PDF for .NET 23.6.