We have service on .Net6, that convert documents from Docx to PDF format. Service has been deployed on Linux container (k8s) and have LibreOffice binary within

LibreOffice has been installed inside container by script below

RUN apt-get update -y
RUN apt-get install -y --no-install-recommends \
        default-jre \
        libreoffice \
        libreoffice-writer \
        ure \
        libreoffice-java-common \
        libreoffice-core \
        libreoffice-common \
        fonts-opensymbol \
        hyphen-fr \
        hyphen-de \
        hyphen-en-us \
        hyphen-it \
        hyphen-ru \
        fonts-dejavu \
        fonts-dejavu-core \
        fonts-dejavu-extra \
        fonts-droid-fallback \
        fonts-dustin \
        fonts-f500 \
        fonts-fanwood \
        fonts-freefont-ttf \
        fonts-liberation \
        fonts-lmodern \
        fonts-lyx \
        fonts-sil-gentium \
        fonts-texgyre \
        fonts-tlwg-purisa

RUN apt-get -y -q remove libreoffice-gnome && \
    apt -y autoremove

RUN rm -rf /var/lib/apt/lists/*

RUN adduser --home=/opt/libreoffice --disabled-password --gecos "" --shell=/bin/bash libreoffice

For converting documents we use invokes soffice via Process and pass arguments List of arguments placed below:

        private List<string> GetCommandArguments(string docx, long userId, string tempFolder)
        {
            return new List<string>
            {
                "--convert-to",
                "pdf:writer_pdf_Export",
                docx,
                $"-env:UserInstallation=file:///{this.options.Value.TempUserPathForArgs}{userId}",
                "--norestore",
                "--writer",
                "--headless",
                "--outdir",
                tempFolder
            };
        }

This configuration works fine, but after some time (approximately after several hours depending on load) we get OutOfMemoryException when trying to invoke LibreOffice Process P.S. Documents converting in Parallel by creating new session(creating temp user) for every process

First Error

Message: "Exception of type 'System.OutOfMemoryException' was thrown.",

StackTrace: at System.Threading.Thread.StartInternal(ThreadHandle t, Int32 stackSize, Int32 priority, Char* pThreadName)\n   at System.Threading.Thread.StartCore()\n   at System.Threading.PortableThreadPool.WaitThread..ctor()\n   at System.Threading.PortableThreadPool.RegisterWaitHandle(RegisteredWaitHandle handle)\n   at System.Threading.ThreadPool.RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, Object state, UInt32 millisecondsTimeOutInterval, Boolean executeOnlyOnce, Boolean flowExecutionContext)\n   at System.Diagnostics.Process.EnsureWatchingForExit()\n   at System.Diagnostics.Process.WaitForExitAsync(CancellationToken cancellationToken)\n   at Gems.IO.LibreOffice.LibreOffice.ConvertToPdfInternalAsync(String docxPath, String pdfPath, CancellationToken cancellationToken)\n 

Second Error

An error occurred trying to start process '/usr/bin/soffice' with working directory '/app'. Resource temporarily unavailable

LibreOffice has failed. Exit code: 2

Exception of type 'System.OutOfMemoryException' was thrown.

How does it fix? What could it be related to?

We dropped all service limits and that didn't help us. But we notice that add more replicas delays OOM

0

There are 0 best solutions below