1
votes

I have two actions, and inside one action I am calling the other one but symfony block on that call until the first one (the one I am calling from) is finished. Therefore due to this fact i am getting time out error. Does anyone know what could be the reason ?

enter image description here

Action is rly simple:

    $url = $this->router->generate(
        'invoice_show',
        [
            'invoiceId' => $invoiceId,
        ],
        UrlGeneratorInterface::ABSOLUTE_URL
    );

    return new Response(
        $this->pdfGenerator->getOutput(
            $url,
            [
                'margin-bottom'       => 3,
                'margin-top'          => 3,
                'margin-left'         => 4,
                'margin-right'        => 4,
                'disable-javascript'  => true,
                'load-error-handling' => 'ignore',
                'cookie'              => $request->cookies->all(),
            ]
        ),
        200,
        [
            'Content-Type'        => 'application/pdf',
            'Content-Disposition' => 'attachment; filename="' . $invoiceId . '.pdf"',
        ]
    );

Exception:

Symfony\Component\Process\Exception\ProcessTimedOutException(code: 0): The process \"/usr/bin/xvfb-run /usr/bin/wkhtmltopdf --lowquality --margin-bottom '3' --margin-left '4' --margin-right '4' --margin-top '3' --disable-javascript --load-error-handling 'ignore' 'http://localhost/invoices/in_1Atlve2rN1gYNyHu4Ixmy8ZI' '/var/www/var/cache/dev/snappy/knp_snappy599cffb13836d0.68608376.pdf'\" exceeded the timeout of 60 seconds. at /var/www/vendor/symfony/symfony/src/Symfony/Component/Process/Process.php:1265

1
Nor sure where your posted code is actually calling another controller but I assume things are getting blocked until the complete pdf file is generated? If so, take a look at streamed responses: symfony.com/doc/current/components/… and stackoverflow.com/questions/32839754/… - Cerad
pdfGenerator calls another action and transforms html to pdf, but the html response never comes. As the application is blocked somehow by the first request where we are w8ing for that pdf file - vardius
I would suggestion you use the Symfony debug URL to test your application. My article Reducing KnpPaginatorBundle Database Queries shows how to use it and some screenshot (3.2 version). Then you could look in the var/logs folder in the dev.log specifically, and see if it explains the 504 errors. That's a server error. Also have you looked at KnpSnappyBundle? It's easy to use. @Cerad 's suggestions are good too. - Alvin Bunk
This is what i am using - vardius
If it's a completely new request then session blocking might be the issue. What kind of session handler do you use? PdoSessionHandler will block subsequent requests until the session is closed in the first one. - Eugene

1 Answers

0
votes

Depending on the session handler which you use with symfony, it might lock the session until the first request is finished. That means all subsequent requests will be blocked to prevent concurrency-issues while writing to the session (writing the same session in two requests might result in losing the first write).

It's the case with PDOSessionHandler, for example.

You can explicitly close the session by calling $request->session->save(); in your controller.

If you don't expect concurrency-issues, e.g. if you don't write to the session at all, you can also disable session locking for the whole application:

session.handler.pdo:
    class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
    public: false
    arguments:
        - "pgsql:host=%database_host%;port=%database_port%;dbname=%database_name%"
        - db_username: %database_user%
          db_password: %database_password%
          db_table: session
          db_id_col: session_id
          db_data_col: session_value
          db_time_col: session_time
          db_lifetime_col: session_lifetime
          lock_mode: 0