Segmentation Fault on AWS Lambda

September 22, 2024
Updated September 22, 2024
Share:

When using AWS Lambda in a Linux container and calling the render method concurrently many times, it sometimes causes the following exception.

Exception:
Error: Runtime exited with error: signal: segmentation fault Runtime.ExitError

Solutions

The solution is to call the GC.Collect method after the PDF document is rendered. We haven't encountered this issue on any other cloud platform. This only started happening in the recent version; the old one with .NET 6 using Amazon Linux 2 is still working.

ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument document = renderer.RenderHtmlAsPdf(htmlString);

GC.Collect();
ChromePdfRenderer renderer = new ChromePdfRenderer();

PdfDocument document = renderer.RenderHtmlAsPdf(htmlString);

GC.Collect();