runtime: Same code starting wkhtmltopdf process works on netcoreapp3.1 but fails on net5.0 on Linux

Description

Repro.

Following code starting process and reading stdout works fine in netcoreapp3.1:

    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "wkhtmltopdf",
                    Arguments =
                        "-q -B 8 -L 8 -R 8 -T 8 --print-media-type --enable-local-file-access -s Letter -O Portrait - -",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    RedirectStandardInput = true,
                    CreateNoWindow = true
                }
            })
            {
                process.Start();

                byte[] array;

                var html = "test";
                using (var standardInput = process.StandardInput)
                {
                    standardInput.WriteLine(html);
                }

                using (var memoryStream = new MemoryStream())
                {
                    using (var baseStream = process.StandardOutput.BaseStream)
                    {
                        var buffer = new byte[4096];
                        int count;
                        while ((count = baseStream.Read(buffer, 0, buffer.Length)) > 0)
                            memoryStream.Write(buffer, 0, count);
                    }

                    var end = process.StandardError.ReadToEnd();
                    if (memoryStream.Length == 0L)
                        throw new Exception(end);
                    process.WaitForExit();
                    array = memoryStream.ToArray();
                }

                Console.WriteLine(array.Length);
            }
        }
    }

but fails in net5.0 with:

System.Exception: QPainter::begin(): Returned false Exit with code 1, due to unknown error.

Configuration

  • dotnet --version: 5.0.101
  • Ubuntu 20.04.1 LTS
  • wkhtmltox_0.12.6-1.bionic_amd64

Regression?

Works in netcoreapp3.1

Other information

related:

  1. https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3119
  2. https://github.com/fpanaccia/Wkhtmltopdf.NetCore/issues/46#issue-772401133
  3. https://github.com/fpanaccia/Wkhtmltopdf.NetCore.Example/issues/14

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 28 (17 by maintainers)

Commits related to this issue

Most upvoted comments

/dev/stdout is a symlink to /proc/PID/fd/1, which is a socket for the process started from .NET 5 with System.Diagnostics.Process with RedirectStandardInput = true. In .NET Core 3.1, it was a pipe, and Linux syscall open works fine with that; the change was made in #34861.

This is indeed the root cause for the issue. open for /dev/stdout fails when it is a socket.

@stephentoub this is a regression caused by changing the Process Streams from pipes to sockets.