Question

I am trying to rasterise a map using wkhtmltoimage. I am spinning up a new process and passing it the command line arguments that are necessary to get the image that I want.

I'm currently suffering from a very long pause when the process is started. I've enabled showing the window to see if there is any dialog related activity that requires user input but there is none. The process sits at 0% CPU for 2 - 3 minutes. Executing the same command on the command like takes a few seconds.

using (Process p = new Process())
{
    ProcessStartInfo info = new ProcessStartInfo(wkhtmlPath, dimensions + EscapeArgument(location) + " -");
    info.UseShellExecute = false;
    info.RedirectStandardOutput = true;
    p.StartInfo = info;
    p.Start();

    byte[] buffer = new byte[32768];
    int read = 0;

    while ((read = p.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length)) > 0)
    {

        //... write bytes to the an ouput buffer
    }

}

It's taking in the order of minutes to complete. This works fine when it doesn't point at one of my controllers using the same session. When it uses the same session, the print controller waits for a response from wkhtmltoimage, which is waiting for the print controller to release the lock so it can get the page. Some timeout must be breaking this deadlock. Can I safely release the session lock somehow?

Was it helpful?

Solution

Controller actions are synchronised on the user session by default in MVC3. Re-issuing a request with the same session token causes a deadlock. The re-issued requests waits for the request from which it was issued to give up the lock on the session. I solved this by not using a session at all for the entry point, but it's probably not the best solution.

Without further investigation, the best solution is to start thinking about asynchronous controllers. Many controller actions I have written are called asynchronously via ajax. This session locking behaviour shows that the controller is synchronising the requests, which is hardly ideal in cases where there session is not even used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top