ProcessTimedOutException when exporting with wkhtmltopdf #715

Closed
opened 2026-02-04 22:02:14 +03:00 by OVERLORD · 11 comments
Owner

Originally created by @tdkl on GitHub (Jun 12, 2018).

For Bug Reports

  • BookStack Version : v0.22.0
  • PHP Version: PHP 7.0.30-0ubuntu0.16.04.1 (cli) ( NTS )
  • MySQL Version: Ver 14.14 Distrib 5.7.22, for Linux (x86_64)
  • Linux Version: Ubuntu Server 16.04 LTS
Expected Behavior

Exported PDF.

Current Behavior

When starting the export of a large page, or whole chapters the export is failing with wkhtmltopdf extension.

Steps to Reproduce

Select Export to PDF option.

chrome_2018-06-12_10-48-38

I imagine it has to be something with the default timeouts of the PHP engine?

Originally created by @tdkl on GitHub (Jun 12, 2018). ### For Bug Reports * BookStack Version : v0.22.0 * PHP Version: PHP 7.0.30-0ubuntu0.16.04.1 (cli) ( NTS ) * MySQL Version: Ver 14.14 Distrib 5.7.22, for Linux (x86_64) * Linux Version: Ubuntu Server 16.04 LTS ##### Expected Behavior Exported PDF. ##### Current Behavior When starting the export of a large page, or whole chapters the export is failing with wkhtmltopdf extension. ##### Steps to Reproduce Select Export to PDF option. ![chrome_2018-06-12_10-48-38](https://user-images.githubusercontent.com/1429957/41280011-399b3826-6e2e-11e8-837b-7423d4fd885f.png) I imagine it has to be something with the default timeouts of the PHP engine?
OVERLORD added the 🐕 Support label 2026-02-04 22:02:14 +03:00
Author
Owner

@TBK commented on GitHub (Jun 15, 2018):

https://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded

I can not give you more specific instruction since I do not how the webserver is talking to php in your setup.

@TBK commented on GitHub (Jun 15, 2018): https://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded I can not give you more specific instruction since I do not how the webserver is talking to php in your setup.
Author
Owner

@tdkl commented on GitHub (Jun 16, 2018):

It was installed on the clean 16.04 Server install with the Ubuntu installer script. I've changed

max_execution_time = 300
max_input_time = 120

in the php.ini, but PDF export still timeouts on larger html pages.

@tdkl commented on GitHub (Jun 16, 2018): It was installed on the clean 16.04 Server install with the Ubuntu installer script. I've changed `max_execution_time = 300` `max_input_time = 120` in the php.ini, but PDF export still timeouts on larger html pages.
Author
Owner

@TBK commented on GitHub (Jun 17, 2018):

Try in settings/snappy.php to change the pdf sections timeout from false to 3600 - b3cc3130f0/config/snappy.php (L7)

@TBK commented on GitHub (Jun 17, 2018): Try in settings/snappy.php to change the pdf sections timeout from false to 3600 - https://github.com/BookStackApp/BookStack/blob/b3cc3130f092ce571f47a67bcd199ead18cdd1f9/config/snappy.php#L7
Author
Owner

@tdkl commented on GitHub (Jun 18, 2018):

@TBK Hi, great tip, it seems that it failed at loading some of the images.

/var/www/bookstack/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php
                'The file \'%s\' was created but is empty (command: %s).',
                $output, $command
            ));
        }
    }
 
    /**
     * Checks the process return status.
     *
     * @param int    $status  The exit status code
     * @param string $stdout  The stdout content
     * @param string $stderr  The stderr content
     * @param string $command The run command
     *
     * @throws \RuntimeException if the output file generation failed
     */
    protected function checkProcessStatus($status, $stdout, $stderr, $command)
    {
        if (0 !== $status and '' !== $stderr) {
            throw new \RuntimeException(sprintf(
                'The exit status code \'%s\' says something went wrong:' . "\n"
                . 'stderr: "%s"' . "\n"
                . 'stdout: "%s"' . "\n"
                . 'command: %s.',
                $status, $stderr, $stdout, $command
            ));
        }
    }
 
    /**
     * Creates a temporary file.
     * The file is not created if the $content argument is null.
     *
     * @param string $content   Optional content for the temporary file
     * @param string $extension An optional extension for the filename
     *
     * @return string The filename
     */
    protected function createTemporaryFile($content = null, $extension = null)
    {
Arguments
"""
The exit status code '1' says something went wrong:\n
stderr: "Loading pages (1/6)\n
[>                                                           ] 0%\r[======>                                                     ] 10%\r[===========================>                                ] 45%\r[============================>                               ] 48%\r[=====================================>                      ] 63%\r[=======================================>                    ] 66%\r[============================================>               ] 74%\r[================================================>           ] 80%\r[=================================================>          ] 83%\r[===================================================>        ] 86%\r[====================================================>       ] 88%\rWarning: Failed to load https://book.mikronis-it.si/uploads/images/gallery/2018-05-May/scaled-840-0/Iq8wMUbFR7CzZZXW-2018-05-05-15_50_21_My-Calendar-_-Vladimir-Putin--Axigen-WebMail.png (ignore)\n ◀
Warning: Failed to load https://book.mikronis-it.si/uploads/images/gallery/2018-05-May/scaled-840-0/8cB1vvNmtqpwQtyO-2018-05-10-21_13_28_Test-_-Tadej-Rudec--Axigen-WebMail.png (ignore)\n ◀
[============================================================] 100%\rCounting pages (2/6)                                               \n
[============================================================] Object 1 of 1\rResolving links (4/6)                                                       \n
[============================================================] Object 1 of 1\rLoading headers and footers (5/6)                                           \n
Printing pages (6/6)\n
[>                                                           ] Preparing\r[====>                                                       ] Page 1 of 14\r[========>                                                   ] Page 2 of 14\r[============>                                               ] Page 3 of 14\r[================>                                           ] Page 4 of 14\r[=====================>                                      ] Page 5 of 14\r[=========================>                                  ] Page 6 of
14\r[==============================>                             ] Page 7 of 14\r[==================================>                         ] Page 8 of 14\r[======================================>                     ] Page 9 of 14\r[==========================================>                 ] Page 10 of 14\r[==============================================>             ] Page 11 of 14\r[===================================================>        ] Page 12 of 14\r[=======================================================>    ] Page 13 of 14\r[============================================================] Page 14 of 14\rDone                                                                        \n ◀
Exit with code 1 due to network error: TimeoutError\n
"\n
stdout: ""\n
command: /var/www/bookstack/wkhtmltopdf --lowquality --print-media-type '/tmp/knp_snappy5b274ec7d434a8.00148987.html' '/tmp/knp_snappy5b274ec7d77785.41891400.pdf'. ◀
"""

Two images which failed to load are attached here:

8cb1vvnmtqpwqtyo-2018-05-10-21_13_28_test-_-tadej-rudec- -axigen-webmail
iq8wmubfr7czzzxw-2018-05-05-15_50_21_my-calendar-_-vladimir-putin- -axigen-webmail

@tdkl commented on GitHub (Jun 18, 2018): @TBK Hi, great tip, it seems that it failed at loading some of the images. ``` /var/www/bookstack/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php 'The file \'%s\' was created but is empty (command: %s).', $output, $command )); } } /** * Checks the process return status. * * @param int $status The exit status code * @param string $stdout The stdout content * @param string $stderr The stderr content * @param string $command The run command * * @throws \RuntimeException if the output file generation failed */ protected function checkProcessStatus($status, $stdout, $stderr, $command) { if (0 !== $status and '' !== $stderr) { throw new \RuntimeException(sprintf( 'The exit status code \'%s\' says something went wrong:' . "\n" . 'stderr: "%s"' . "\n" . 'stdout: "%s"' . "\n" . 'command: %s.', $status, $stderr, $stdout, $command )); } } /** * Creates a temporary file. * The file is not created if the $content argument is null. * * @param string $content Optional content for the temporary file * @param string $extension An optional extension for the filename * * @return string The filename */ protected function createTemporaryFile($content = null, $extension = null) { Arguments """ The exit status code '1' says something went wrong:\n stderr: "Loading pages (1/6)\n [> ] 0%\r[======> ] 10%\r[===========================> ] 45%\r[============================> ] 48%\r[=====================================> ] 63%\r[=======================================> ] 66%\r[============================================> ] 74%\r[================================================> ] 80%\r[=================================================> ] 83%\r[===================================================> ] 86%\r[====================================================> ] 88%\rWarning: Failed to load https://book.mikronis-it.si/uploads/images/gallery/2018-05-May/scaled-840-0/Iq8wMUbFR7CzZZXW-2018-05-05-15_50_21_My-Calendar-_-Vladimir-Putin--Axigen-WebMail.png (ignore)\n ◀ Warning: Failed to load https://book.mikronis-it.si/uploads/images/gallery/2018-05-May/scaled-840-0/8cB1vvNmtqpwQtyO-2018-05-10-21_13_28_Test-_-Tadej-Rudec--Axigen-WebMail.png (ignore)\n ◀ [============================================================] 100%\rCounting pages (2/6) \n [============================================================] Object 1 of 1\rResolving links (4/6) \n [============================================================] Object 1 of 1\rLoading headers and footers (5/6) \n Printing pages (6/6)\n [> ] Preparing\r[====> ] Page 1 of 14\r[========> ] Page 2 of 14\r[============> ] Page 3 of 14\r[================> ] Page 4 of 14\r[=====================> ] Page 5 of 14\r[=========================> ] Page 6 of 14\r[==============================> ] Page 7 of 14\r[==================================> ] Page 8 of 14\r[======================================> ] Page 9 of 14\r[==========================================> ] Page 10 of 14\r[==============================================> ] Page 11 of 14\r[===================================================> ] Page 12 of 14\r[=======================================================> ] Page 13 of 14\r[============================================================] Page 14 of 14\rDone \n ◀ Exit with code 1 due to network error: TimeoutError\n "\n stdout: ""\n command: /var/www/bookstack/wkhtmltopdf --lowquality --print-media-type '/tmp/knp_snappy5b274ec7d434a8.00148987.html' '/tmp/knp_snappy5b274ec7d77785.41891400.pdf'. ◀ """ ``` Two images which failed to load are attached here: ![8cb1vvnmtqpwqtyo-2018-05-10-21_13_28_test-_-tadej-rudec- -axigen-webmail](https://user-images.githubusercontent.com/1429957/41521516-c4548bcc-72d2-11e8-8bb0-aae12f212dd7.png) ![iq8wmubfr7czzzxw-2018-05-05-15_50_21_my-calendar-_-vladimir-putin- -axigen-webmail](https://user-images.githubusercontent.com/1429957/41521517-c472d078-72d2-11e8-8c08-7262d8bcc1a2.png)
Author
Owner

@TBK commented on GitHub (Jun 18, 2018):

Could I get you to check which version of wkhtmltopdf you have installed?
/var/www/bookstack/wkhtmltopdf -V

I tried to resolve on of the image urls and it returns a 401 (auth required) it is a possibility that it is the same issue that is causing wkhtmltopdf to fail.

@TBK commented on GitHub (Jun 18, 2018): Could I get you to check which version of wkhtmltopdf you have installed? `/var/www/bookstack/wkhtmltopdf -V` I tried to resolve on of the image urls and it returns a 401 (auth required) it is a possibility that it is the same issue that is causing wkhtmltopdf to fail.
Author
Owner

@tdkl commented on GitHub (Jun 18, 2018):

v12.4, but I just saw that v12.5 is out for couple days. Same issue with it.

Only difference when trying with v12.5 is that the error message was Socket operation timed out:

Error: Failed to load https://book.mikronis-it.si/uploads/images/gallery/2018-05-May/scaled-840-0/R0n4rFycGCtZIEcn-2018-05-05-21_09_49_[2]-Total-Commander-(x64)-9.12---Tadej-Rudec.png, with network status code 4 and http status code 0 - Socket operation timed out\n

Yes, it's a private documentation server, but if the authorization was an issue, it would fail with all images on all exports. I also disabled it for a test, but same error persisted.

@tdkl commented on GitHub (Jun 18, 2018): v12.4, but I just saw that v12.5 is out for couple days. Same issue with it. Only difference when trying with v12.5 is that the error message was Socket operation timed out: ``` Error: Failed to load https://book.mikronis-it.si/uploads/images/gallery/2018-05-May/scaled-840-0/R0n4rFycGCtZIEcn-2018-05-05-21_09_49_[2]-Total-Commander-(x64)-9.12---Tadej-Rudec.png, with network status code 4 and http status code 0 - Socket operation timed out\n ``` Yes, it's a private documentation server, but if the authorization was an issue, it would fail with all images on all exports. I also disabled it for a test, but same error persisted.
Author
Owner

@TBK commented on GitHub (Jun 18, 2018):

Are the working image urls relative or absolute?

@TBK commented on GitHub (Jun 18, 2018): Are the working image urls relative or absolute?
Author
Owner

@tdkl commented on GitHub (Jun 18, 2018):

All images are absolute.

@tdkl commented on GitHub (Jun 18, 2018): All images are absolute.
Author
Owner

@TBK commented on GitHub (Jun 18, 2018):

I only got couple of things left that could possible cause the issue:

  1. Check that /tmp/knp_snappy5b274ec7d434a8.00148987.html is valid HTML.
  2. Characters in the file name that it does not like.
  3. It could be an issue with the images encoding.

If it is not 1 then I think we have established that the issue is contained to wkhtmltopdf.

@TBK commented on GitHub (Jun 18, 2018): I only got couple of things left that could possible cause the issue: 1. Check that `/tmp/knp_snappy5b274ec7d434a8.00148987.html` is valid HTML. 2. Characters in the file name that it does not like. 3. It could be an issue with the images encoding. If it is not 1 then I think we have established that the issue is contained to wkhtmltopdf.
Author
Owner

@tdkl commented on GitHub (Jun 19, 2018):

Great tips @TBK , I've checked the .pdf in /tmp and saw the the certain images were indeed missing.

It seems that filenames containing []% characters were failing at export. When renaming the images, reuploading them and readding to the page the pdf export was instant (so adding the timeout wasn't actually needed).

This notice regarding image naming could be perhaps added to the installation or usage guide.

@tdkl commented on GitHub (Jun 19, 2018): Great tips @TBK , I've checked the .pdf in `/tmp` and saw the the certain images were indeed missing. It seems that filenames containing []% characters were failing at export. When renaming the images, reuploading them and readding to the page the pdf export was instant (so adding the timeout wasn't actually needed). This notice regarding image naming could be perhaps added to the installation or usage guide.
Author
Owner

@TBK commented on GitHub (Jun 19, 2018):

File upload could sanitize the file name. What do you think @ssddanbrown ?

@TBK commented on GitHub (Jun 19, 2018): File upload could sanitize the file name. What do you think @ssddanbrown ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#715