We have a .NET web application that uses Aspose.Words to convert RTF files to PDF. This application has been running fine in IIS on a Windows VM for a number of years, but we’ve recently started running it on a Linux container in Microsoft Azure. We’ve discovered that when we attempt to convert files that contain images, Azure–we presume it’s the underlying Kubernetes infrastructure–terminates our container with this message:
Container was terminated with exit code “139” and reason “ProcessExited”
Sometimes this message appears the first time I hit the endpoint; other times I can get a successful response one or two times before the application is terminated.
When we run our application in a Docker container on our local development machines, we’re not able to produce this issue–which makes sense as it appears to be a safeguard in place within Azure to protect against invalid memory access.
We were able to reproduce this with just a few lines of code. Here is an API controller method:
[HttpPut("test")]
[Consumes("multipart/form-data")]
public async Task<string> Test(IFormFile file)
{
using var ms = new MemoryStream();
await file.CopyToAsync(ms);
var doc = new Aspose.Words.Document(ms, new LoadOptions { LoadFormat = LoadFormat.Rtf });
using var targetStream = new MemoryStream();
doc.Save(targetStream, SaveOptions.CreateSaveOptions(SaveFormat.Pdf));
return $"Converted form {file.FileName} to PDF of size {targetStream.Length} bytes";
}
The issue can be reproduced by sending it the RTF file found in this zip: test.zip (18.7 KB)
Additionally, we have included the following in our docker file:
RUN apt-get update && apt-get install -y libgdiplus
RUN apt-get install software-properties-common -y
RUN echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
RUN apt-get update && apt-get upgrade -y
RUN apt-get install ttf-mscorefonts-installer -y
RUN apt-get update && apt-get install -y libfontconfig1
The exit code 139 typically indicates a segmentation fault, which can occur due to invalid memory access. Since your application works locally but fails in the Azure Kubernetes environment, it suggests that there might be differences in the environment or resource limitations.
Here are several steps you can take to troubleshoot and potentially resolve the issue:
Increase Memory Limits: Ensure that your container has sufficient memory allocated. Insufficient memory can lead to crashes when processing large files or images.
Check Image Formats: Verify that the images in your RTF files are in a supported format. Unsupported or corrupted image formats can cause issues during conversion.
Use a Different Base Image: If you are using a specific base image for your Docker container, consider switching to a different one that may have better compatibility with Aspose.Words.
Implement Logging: Add detailed logging in your application to capture more information about the application’s state when the error occurs. This can help identify the specific operation that leads to the crash.
Test with Different Files: Try converting various RTF files with different content and images to determine if the issue is specific to certain files.
Update Aspose.Words: Ensure you are using the latest version of Aspose.Words, as updates may include bug fixes and improvements that could resolve the issue.
If the problem persists, consider reaching out to Aspose support with detailed logs and the specific RTF file that causes the issue for further assistance.
If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:
If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies , which does not require installation of libfontconfig1.