Concurrent convert requests using OfficeToPDF crashes application in Azure app services

Product: PDF tron SDK

Product Version: 9.1.0-f7d9a2419c

Please give a brief summary of your issue:
Triggering concurrent conversions on Azure app services crashes application

Please describe your issue and provide steps to reproduce it:
We have an app service in Azure that converts docx files to PDF using pdftron.PDF.Convert.OfficeToPDF()
The service and conversions work fine on on premise, with concurrent convert operations.
But in Azure if there are concurrent convert operations, the program crashes.
We have isolated the issue by commenting actual function,
->pdftron.PDF.Convert.OfficeToPDF(doc, filePath, null);
and replacing with a Task.Delay(), and the service does not crash.
Each request converts a new document, so the PDFDoc is not shared across threads.
Also used Lock() on PDFDoc, but same result.

Please provide a link to a minimal sample where the issue is reproducible:

We are using just a SDK method

public string Convert(string filePath, Guid jobId, string tenantId)
        {
            var convertedFileLocalPath = _storagePaths.GetTenantLocalFolderForConversion(filePath, jobId, tenantId);
            using (PDFDoc doc = new PDFDoc())
            {
                if (!Directory.Exists(convertedFileLocalPath))
                    Directory.CreateDirectory(convertedFileLocalPath);

                convertedFileLocalPath = Path.Combine(convertedFileLocalPath, Path.GetFileNameWithoutExtension(filePath)) + ".pdf";
                pdftron.PDF.Convert.OfficeToPDF(doc, filePath, null);

                doc.Save(convertedFileLocalPath, SDFDoc.SaveOptions.e_linearized);
            }
            return convertedFileLocalPath;
        }

Any help would be appreciated.

Stack trace of error:

doc = new PDFDoc()

// Converter tries to invoke -> pdftron.PDF.Convert.OfficeToPDF(doc, filePath, null);
Application:2022-01-08 10:08:59.430 +00:00 [Information] .FormatConverter.Jobs.ConversionJob: JobId: 8886222b-b18b-4e78-bcb6-632550cfa95b, tenantId; https://patest3.dev.online.com/: CONVERTER: Converting... convertedFileLocalPath c:\local\temp\aHR0cHM6Ly9wYXRlc3QzLmRldi5wcm9hcmNvbmxpbmUuY29tLw==\8886222b-b18b-4e78-bcb6-632550cfa95b\Conversion\formatConvert_02_006.pdf

// Application just crashes below
Application:2022-01-08 10:08:59.899 +00:00 [Information] Microsoft.Hosting.Lifetime: Application is shutting down...
Application:2022-01-08 10:08:59.899 +00:00 [Trace] Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager: Ending connection heartbeat.
Application:2022-01-08 10:09:00.687 +00:00 [Trace] Hangfire.Server.ServerJobCancellationWatcher: Checking for aborted jobs...
Application:2022-01-08 10:09:00.687 +00:00 [Trace] Hangfire.Server.ServerJobCancellationWatcher: No newly aborted jobs found.
Application:2022-01-08 10:09:00.765 +00:00 [Debug] Microsoft.Extensions.Http.DefaultHttpClientFactory: Starting HttpMessageHandler cleanup cycle with 1 items
Application:2022-01-08 10:09:00.766 +00:00 [Debug] Microsoft.Extensions.Http.DefaultHttpClientFactory: Ending HttpMessageHandler cleanup cycle after 0.0012ms - processed: 0 items - remaining: 1 items
Application:2022-01-08 10:09:00.767 +00:00 [Debug] Microsoft.Extensions.Hosting.Internal.Host: Hosting stopping
Application:2022-01-08 10:09:00.768 +00:00 [Debug] Hangfire.BackgroundJobServer: Hangfire Server is stopping...
Application:2022-01-08 10:09:00.768 +00:00 [Information] Hangfire.Server.BackgroundServerProcess: Server dw1sdwk0004l6:6252:228d7ae6 caught stopping signal...
Application:2022-01-08 10:09:00.777 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop ServerJobCancellationWatcher:ade992fc stopped in 8.4886 ms
Application:2022-01-08 10:09:00.778 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop RecurringJobScheduler:c4a0697e stopped in 8.9292 ms
Application:2022-01-08 10:09:00.778 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop DelayedJobScheduler:a5515b24 stopped in 9.1389 ms
Application:2022-01-08 10:09:00.778 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop CountersAggregator:48a36048 stopped in 9.3273 ms
Application:2022-01-08 10:09:00.778 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop ServerWatchdog:d529790e stopped in 9.5274 ms
Application:2022-01-08 10:09:00.778 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop ExpirationManager:195d43fd stopped in 9.7482 ms
Application:2022-01-08 10:09:00.786 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop Worker:a6bf19a6 stopped in 17.7533 ms
Application:2022-01-08 10:09:00.787 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop Worker:b1151c85 stopped in 18.0346 ms
Application:2022-01-08 10:09:00.787 +00:00 [Debug] Hangfire.Processing.BackgroundExecution: Execution loop Worker:6a44b871 stopped in 18.3007 ms
Application:2022-01-08 10:09:01.001 +00:00 [Information] Hangfire.Server.BackgroundServerProcess: Server dw1sdwk0004l6:6252:228d7ae6 caught stopped signal...
Application:2022-01-08 10:09:02.817 +00:00 [Error] .FormatConverter.Jobs.ConversionJob: JobId: 8886222b-b18b-4e78-bcb6-632550cfa95b, tenantId; https://patest3.dev.online.com/: CONVERSION FAILED !! Exception: pdftron.Common.PDFNetException: Exception: 
Application:	 Message: document layout failed: bad allocation
Application:	 Conditional expression: 
Application:	 Version      : 9.1.0-f7d9a2419c
Application:	 Platform     : Windows
Application:	 Architecture : AMD64
Application:	 Filename     : FlowToPDFConversion.cpp
Application:	 Function     : PDF::DocxConversion::Convert()
Application:	 Linenumber   : 189
Application:
Application:   at pdftron.Common.PDFNetException.REX(IntPtr result)
Application:   at pdftron.PDF.Convert.OfficeToPDF(PDFDoc inDoc, String inFilename, ConversionOptions options)
Application:   at .FormatConverter.Jobs.Converters.OfficeToPdfConverter.Convert(String filePath, Guid jobId, String tenantId) in C:\Users\MubeenAsim\source\repos\formatconverter3\Source\.FormatConverter.Jobs\Converters\OfficeToPdfConverter.cs:line 37

Could you please confirm what memory is available on your Azure app (versus memory available on-premises)?

Also what is your limit/peak concurrent conversions?

@Ryan I’m getting the same error in Azure while it works locally. Are you saying this is an available memory issue?

Exception: 
	 Message: document layout failed: bad allocation
	 Conditional expression: 
	 Version      : 9.2.0-91be0af529
	 Platform     : Windows
	 Architecture : AMD64
	 Filename     : FlowToPDFConversion.cpp
	 Function     : PDF::DocxConversion::Convert()
	 Linenumber   : 189

Yes, the “bad allocation” error is from the C++ runtime and typically means it was unable to allocate memory on the heap.

How much memory is consumed when you run locally?
How much memory does your Azure instance have available?
Also what is your limit/peak concurrent conversions?
How many concurrent conversions are occurring when the “bad alloc” happens?
Can you reproduce everytime? How long does it take?