Segmentation Fault on AWS Lambda

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.

// Create an instance of ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render the HTML string to a PDF document
PdfDocument document = renderer.RenderHtmlAsPdf(htmlString);

// Explicitly trigger garbage collection to help manage memory usage
GC.Collect();
// Create an instance of ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render the HTML string to a PDF document
PdfDocument document = renderer.RenderHtmlAsPdf(htmlString);

// Explicitly trigger garbage collection to help manage memory usage
GC.Collect();
' Create an instance of ChromePdfRenderer
Dim renderer As New ChromePdfRenderer()

' Render the HTML string to a PDF document
Dim document As PdfDocument = renderer.RenderHtmlAsPdf(htmlString)

' Explicitly trigger garbage collection to help manage memory usage
GC.Collect()
$vbLabelText   $csharpLabel
Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 15,842,959 | Version: 2025.10 just released