Segmentation Fault on AWS Lambda

This article was translated from English: Does it need improvement?
Translated
View the article in English

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
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado