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. This issue has been reported on Amazon Linux 2023 with recent IronPDF versions; earlier deployments using .NET 6 and Amazon Linux 2 are not affected.
// 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()
Multi-Process Rendering and wstring_convert::from_bytes Errors
If GC.Collect() does not resolve the issue, the root cause may be multi-process rendering or global ChromePdfRenderer reuse within the Lambda container. This produces either a segmentation fault or a C++ exception:
Process runtime-1 exited: signal: segmentation fault
Error while generating PDF from HTML: 'wstring_convert::from_bytes'
These errors are intermittent and may only appear after the first or second Lambda container invocation.
Solution
Set Installation.SingleProcess = true, redirect paths to /tmp, and create a new ChromePdfRenderer per invocation:
IronPdf.Installation.SingleProcess = true;
IronPdf.Installation.TempFolderPath = "/tmp";
var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync(htmlString);
IronPdf.Installation.SingleProcess = true;
IronPdf.Installation.TempFolderPath = "/tmp";
var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync(htmlString);
Imports IronPdf
IronPdf.Installation.SingleProcess = True
IronPdf.Installation.TempFolderPath = "/tmp"
Dim renderer As New ChromePdfRenderer()
Dim pdf = Await renderer.RenderHtmlAsPdfAsync(htmlString)
Do not call Installation.Initialize() and do not hold a ChromePdfRenderer as a static or field-level instance. A persistent renderer carries stale memory state into subsequent Lambda invocations and causes the crash.
// Avoid: global renderer reuse
private readonly ChromePdfRenderer _renderer = new();
// Avoid: calling Initialize()
Installation.Initialize();
// Avoid: global renderer reuse
private readonly ChromePdfRenderer _renderer = new();
// Avoid: calling Initialize()
Installation.Initialize();

