Sicos1977 / ChromiumHtmlToPdf

Convert HTML to PDF with a Chromium based browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chrome creates bunch of zombie processes (Linux/Ubuntu)

vitosaver opened this issue · comments

Hi,

I am aware that this might not be related to the library at all but wanted to check with you anyway.

So basically what happens after PDF generation is done system is left with 6 zombie processes.
image

Is it possible that Chrome is not closed gracefully after the job, most often this happens when you kill a parent and he didn't have a chance to close its child processes?

Please let me know if you have some ideas from the top of your head and then I will investigate further.

Tnx,
Vito

commented

In the latest version I added logging to see if Chrome was closed gracefully. When it does than this is logged. If for some reason Chrome wont close gracefully I take the PID, lookup all the child processes and kill them.

You should check if you see this kind of logging

WriteToLog($"Disposing websocket connection to url '{_url}'");
WriteToLog("Websocket connection disposed");
WriteToLog("Closing Chrome browser gracefully");
WriteToLog("Chrome closed gracefully");

If it did not close gracefully you will see something like this

WriteToLog($"Chrome did not close gracefully, closing it by killing it's process on id '{_chromeProcess.Id}'");
WriteToLog("Chrome killed");

        #region KillProcessAndChildren
        /// <summary>
        ///     Kill the process with given id and all it's children
        /// </summary>
        /// <param name="processId">The process id</param>
        private void KillProcessAndChildren(int processId)
        {
            if (processId == 0) return;

            try
            {
                var process = Process.GetProcessById(processId);
                process.Kill();
            }
            catch (Exception exception)
            {
                if (!exception.Message.Contains("is not running"))
                    WriteToLog(exception.Message);
            }
        }
        #endregion

So I just checked logs I am getting Chrome closed gracefully message.

I don't know, what to think of it. It must be a chrome bug then. I will do a little more research on the internet even though I didn't find much till now.

Thanks anyway for checking it out.

If people wonder about this issue here is how I solved it:

You can use --init flag when running docker, but if you are using something like Kubernetes then you will have to embed tini into your Dockerfile

Basically tini runs containers in separate PIDs and takes care of all zombie processes.

Just add something like this in your dockerfile:

# install tini to act as init 
RUN apt-get update && apt-get install -y tini &&\
    rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["tini", "--", "dotnet", "Web.dll"]

如果人们想知道这个问题,我是如何解决的:

你可以--init在运行 docker 时使用 flag,但如果你使用的是 Kubernetes 之类的东西,那么你必须将tini嵌入到你的 Dockerfile 中

基本上,tini 在单独的 PID 中运行容器并处理所有僵尸进程。

只需在您的 dockerfile 中添加类似的内容:

# install tini to act as init 
RUN apt-get update && apt-get install -y tini &&\
    rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["tini", "--", "dotnet", "Web.dll"]

Do you have this problem?
image

The local Windows development environment is running properly, and an error is reported when you put it on the Ubuntu20.04 server. What is the reason for this?
Dockerfile added content to download and install Chrome.