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