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

Wkhtmltopdf failed (error code: -11). Message: - when only empty content is to be drawn on the last page #2711

Closed
radoslaw opened this Issue Dec 10, 2015 · 25 comments

Comments

Projects
None yet
8 participants
@radoslaw

radoslaw commented Dec 10, 2015

Hi guys, this happens with odoo 8 and ubuntu 12 but all that is not relevant
i figured the cause of the issue is that when there is only empty content (such as margin) to be drawn on the last page.
In my case, under order items, there is a summary defined with a table that has bottom margin set to 20
if i increase or decrease the number of products shown, the content moves up or down on the page and pdf comes out without errors
what i did to fix it was modify xml to always break the page before the summary section
BUT this is a fix for this particular report while Wkhtmltopdf is still subject to fail for other reports when printing empty content on last page...
Here is a screen grab of the html that gets sent to the converter (table class has style of margin-bottom: 20px;):
screen shot 2015-12-10 at 11 35 31

@radoslaw

This comment has been minimized.

radoslaw commented Dec 10, 2015

I am using wkhtmltopdf 0.12.3-dev-279a3f6 (with patched qt) compiled specifically for our server

@radoslaw

This comment has been minimized.

radoslaw commented Dec 18, 2015

our server is running Ubuntu 12.04.5 LTS Linux 3.1.9-vs2.3.2.5vs2.3.2.5+

@radoslaw

This comment has been minimized.

radoslaw commented Feb 19, 2016

If it helps, it happens for that particular data set with report printing to pdf into US letter landscape. The same report prints just fine into US letter [portrait]

@taifu

This comment has been minimized.

taifu commented Feb 23, 2016

We temporarily solved this issue putting table width=99% into the template. This caused the last page to have some content. This is clearly only a "quick and dirty" workaround.

@radoslaw

This comment has been minimized.

radoslaw commented Feb 23, 2016

do you mean that
<table class="table table-condensed">
became
<table class="table table-condensed" style="width: 99%;">
the one that holds heading and data rows?

our previous fix was to page break on the summary table but that did not always work
<div class="row" style="page-break-before: always;">
<div class="col-xs-4 pull-right">
<table class="table table-condensed">

is your issue related to a particular paper size/format?

@taifu

This comment has been minimized.

taifu commented Feb 23, 2016

Radoslaw, a part of your message is missing.
By the way:

<t t-call="l10n_it_account.internal_layout"> <div class="page"> <t t-set="print_details" t-value="1"/> <t t-if="only_totals == True"> <t t-set="print_details" t-value="0"/> </t> <table style="width:100%; font-size: small;" cellspacing="0">

Became:

<t t-call="l10n_it_account.internal_layout"> <div class="page"> <t t-set="print_details" t-value="1"/> <t t-if="only_totals == True"> <t t-set="print_details" t-value="0"/> </t> <table style="width:99%; font-size: small;" cellspacing="0">

This fix is a dirty workaround that caused the last page to be not empty.

@yelizariev

This comment has been minimized.

yelizariev commented Mar 8, 2016

I think the reason in memory shortage and all workarounds simply reduce memory usage.

Try increase value for limit_memory_hard parameter in odoo config file

@taifu

This comment has been minimized.

taifu commented Mar 8, 2016

Yelizariev, I think you are wrong we duplicated the memory without resolving. We left the original limit_memory_hard value and 99% in the width and the problem went away.

@Yajo

This comment has been minimized.

Yajo commented Dec 12, 2017

This must indeed be happening. I'm experiencing a very corner case, but at the end it's interesting that before wkhtmltopdf segfaults, if I remove the --quiet flag from its CLI, it prints this at the end:

Printing pages      (6/6)                                               
[>                                                           ] 
Preparing
[===================>                                        ] 
Page 1 of 3
[=======================================>                    ] 
Page 2 of      3
[============================================================] 
Page 3 of                   3
[============================================================] 
Page 4 of 3

Did you notice the last part? Page 4 of 3 clearly seems like a wrong page amount calculation taking place at the beginning and producing an error when at the end it turns out it should have printed a 4th page.

Besides I also increased the hard memory limit above 32GB, so that couldn't be the problem.

@Yajo

This comment has been minimized.

Yajo commented May 11, 2018

Well, I finally digged it down to a reproducible case.

The title of this issue should be misleading for wkhtmltopdf developers. For some unkown reason (maybe this one?), while running Odoo (in Python), it detects the exit code -11 for these errors.

However, running the exact same command in bash returns 139 as exit code.

I have exported a report that fails, and anonymized all things. You have it here: reproducible-case.zip

Open it, uncompress it, open bash in its folder, and execute ./script.sh to get the failure.

According to my test-based intuition (lol), it always happens when for some random reason a table row should land in 2 pages at the same time. It just dies badly.

The test case is not so narrow as you would desire, but it's a proof that wkhtmltopdf 0.12.4 (with patched qt) (official build) dies and that this issue exists and we're not crazy.

If you want, just search through the code of the body.html file that is inside the ZIP and find a line that contains: <!-- REMOVE ME AND REJOICE -->. Do it; remove that line and try again. It should work.

I hope this really helps the developers to find the issue and fix it finally! (you know, 3 years of random failures is pretty nasty 😭)

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 12, 2018

I tried to reproduce it, but it doesn't crash for me on Ubuntu 18.04.

wkhtmltopdf 0.12.4 (with patched qt)
Loading pages (1/6)
QSslSocket: cannot resolve CRYPTO_num_locks                  ] 10%
QSslSocket: cannot resolve CRYPTO_set_id_callback
QSslSocket: cannot resolve CRYPTO_set_locking_callback
QSslSocket: cannot resolve sk_free
QSslSocket: cannot resolve sk_num
QSslSocket: cannot resolve sk_pop_free
QSslSocket: cannot resolve sk_value
QSslSocket: cannot resolve SSL_library_init
QSslSocket: cannot resolve SSL_load_error_strings
QSslSocket: cannot resolve SSLv3_client_method
QSslSocket: cannot resolve SSLv23_client_method
QSslSocket: cannot resolve SSLv3_server_method
QSslSocket: cannot resolve SSLv23_server_method
QSslSocket: cannot resolve X509_STORE_CTX_get_chain
QSslSocket: cannot resolve OPENSSL_add_all_algorithms_noconf
QSslSocket: cannot resolve OPENSSL_add_all_algorithms_conf
QSslSocket: cannot resolve SSLeay
QSslSocket: cannot call unresolved function CRYPTO_num_locks
QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function sk_num
QSslSocket: cannot call unresolved function SSLv23_client_method8%
QSslSocket: cannot call unresolved function SSL_library_init
Counting pages (2/6)                                               
Resolving links (4/6)                                                       
Loading headers and footers (5/6)                                           
QSslSocket: cannot call unresolved function SSLv23_client_method0%
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function SSLv23_client_method00%
QSslSocket: cannot call unresolved function SSL_library_init
Printing pages (6/6)                                               
Done                                                                      
Exit with code 1 due to network error: UnknownNetworkError
QSslSocket: cannot call unresolved function CRYPTO_num_locks
QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback
exit code: 1

The SSL errors are because of #3001, not sure if they are relevant to your testcase. Can you let me know what OS you are running on and what packages/fonts are installed?

@Chouchen

This comment has been minimized.

Chouchen commented May 14, 2018

Tried with an old version on Debian 8.10 :

./script.sh 
wkhtmltopdf 0.12.2.1 (with patched qt)
Loading pages (1/6)
Counting pages (2/6)                                               
Resolving links (4/6)                                                       
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
exit code: 0

then tried with 0.12.4 :

./script.sh 
wkhtmltopdf 0.12.4 (with patched qt)
Loading pages (1/6)
Counting pages (2/6)                                               
Resolving links (4/6)                                                       
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
exit code: 0

Same result if I remove the commented line.

Anyway, I have this problem for one of my client : random error 11, if I add one or two <br> it goes smoothly but another page can have the error with the added <br>.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 15, 2018

Looks like this is very much environment specific, so can't debug it without a reproducible crash.

@Yajo

This comment has been minimized.

Yajo commented May 15, 2018

With this Dockerfile:

FROM debian:8
ARG WKHTMLTOPDF_VERSION=0.12.4
ARG WKHTMLTOPDF_CHECKSUM='049b2cdec9a8254f0ef8ac273afaf54f7e25459a273e27189591edc7d7cf29db'
RUN apt-get update && apt-get install -yqq --no-install-recommends \
        fontconfig libfreetype6 libxml2 libxslt1.1 libjpeg62-turbo zlib1g \
        libfreetype6 liblcms2-2 libtiff5 tk tcl libpq5 \
        libldap-2.4-2 libsasl2-2 libx11-6 libxext6 libxrender1 \
        locales-all zlibc \
        bzip2 ca-certificates curl gettext-base git gnupg2 nano \
        openssh-client telnet unzip xz-utils
RUN curl -SLo wkhtmltox.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/${WKHTMLTOPDF_VERSION}/wkhtmltox-${WKHTMLTOPDF_VERSION}_linux-generic-amd64.tar.xz \
    && echo "${WKHTMLTOPDF_CHECKSUM}  wkhtmltox.tar.xz" | sha256sum -c - \
    && tar --strip-components 1 -C /usr/local/ -xf wkhtmltox.tar.xz \
    && rm wkhtmltox.tar.xz \
    && wkhtmltopdf --version
RUN curl -SLo /root/reproducible-case.zip https://github.com/wkhtmltopdf/wkhtmltopdf/files/1995334/reproducible-case.zip
WORKDIR /root
RUN unzip reproducible-case.zip
CMD [ "./script.sh" ]
RUN mkdir -p /opt/odoo/auto/addons/

Build it and execute it:

docker image build --tag test .
docker container run --rm -it test

Results in my machine:

wkhtmltopdf 0.12.4 (with patched qt)
Loading pages (1/6)
Counting pages (2/6)                                               
Resolving links (4/6)                                                       
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Segmentation fault (core dumped)=============================] Page 3 of 2
exit code: 139
@ashkulz

This comment has been minimized.

Member

ashkulz commented May 15, 2018

@Yajo: thanks, I'll take a look. It clearly shows the off-by-one error (page 3 of 2). Wish more people gave such a comprehensive and reproducible bug report!

@Yajo

This comment has been minimized.

Yajo commented May 16, 2018

Thank you, it took me hours to get a completely reproducible case! This is a hard bug...

If you fix it, I think you'll get a 🏆 in the next OCA Code Sprint, if you want to come see us! 😊

@ashkulz ashkulz added Verified and removed NeedToVerify labels May 22, 2018

@ashkulz ashkulz added this to the 0.12.5 milestone May 22, 2018

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 22, 2018

So, haven't really had time to look into this (working on finishing builds for macOS and Windows) yet, hopefully will do it early next week.

@OskarStark

This comment has been minimized.

OskarStark commented May 25, 2018

@ashkulz any idea when the new version will be released?

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 25, 2018

Final release will hopefully with a fix for this issue, rc with builds for all platforms out this weekend.

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jun 4, 2018

So, 6f77c46 should fix this issue. For the specific testcase above, it would generate 3 pages (due to the layout changes between phases) vs 2 pages generated consistently now. As a bonus, it should also speed up the "printing" phase.

I've triggered off the creation of a new -rc build, which should take ~10-12 hours to complete.

@ashkulz ashkulz removed the Verified label Jun 4, 2018

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jun 4, 2018

So, the release candidate with fix is now up via 2cf4f5b. Please test and report back if you face any issues -- barring any build system changes, this will be what gets released this weekend.

@ashkulz ashkulz closed this Jun 4, 2018

@joshuapancho

This comment has been minimized.

joshuapancho commented Jun 7, 2018

Hi @ashkulz, is there a rough date scheduled for the next official release of wkhtmltopdf? I'm interested in this particular fix for a codebase at work, but hesitant to use the release candidate given some requirements and policies we have around what packages/libraries we use on our projects.

@Yajo

This comment has been minimized.

Yajo commented Jun 7, 2018

I tested on the test case I gave you and with production cases, and it works! Thanks!! 😻

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jun 7, 2018

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jun 11, 2018

0.12.5 has been released, builds for all platforms will be uploaded in 5-6 hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment