Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StopThread() cannot stop the newly opened background thread, resulting in unlimited thread growth and eventually breaking the Linux system limit. #186

Open
hkszlq opened this issue Jun 22, 2024 · 0 comments

Comments

@hkszlq
Copy link

hkszlq commented Jun 22, 2024

in src/DinkToPdf/SynchronizedConverter.cs

private void StopThread()
{
lock (startLock)
{
if (conversionThread != null)
{
kill = true;
while (conversionThread.ThreadState == ThreadState.Stopped)
{
}
conversionThread = null;
}
}
}

 private void StartThread()
    {
        lock (startLock)
        {
            if (conversionThread == null)
            {
                conversionThread = new Thread(**Run**)
                {
                    IsBackground = true,
                    Name = "wkhtmltopdf worker thread"
                };

                kill = false;

                conversionThread.Start();
            }
        }
    }

private void Run()
{
while (!kill)
{
//get next conversion taks from blocking collection
Task task = conversions.Take();

            lock (task)
            {
                //run taks on thread that called RunSynchronously method
                task.RunSynchronously();

                //notify caller thread that task is completed
                Monitor.Pulse(task);
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant