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
Simple PDF crashes uwsgi #399
Comments
I'll need some information about how pikepdf is being used in this application. In particular it will be important to try to determine what objects are being accessed and retained. It would also be helpful to know if you're able to reproduce this on pikepdf < 6. The following produces nothing exciting: def test_z3c():
rml2pdf = pytest.importorskip("z3c.rml.rml2pdf")
data = rml2pdf.parseString(XML)
for _ in range(1000):
with pikepdf.open(data) as pdf:
pass
gc.collect() |
I am not processing PDF using pikepdf, i am not calling any function, there is only import in z3c.rml - https://github.com/zopefoundation/z3c.rml/blob/fe8a2d4c8cf1091318bd1d7144249b17dd007b0d/src/z3c/rml/page.py This import crashes uwsgi with pikepdf 5.x and 6.x. I have not tested other versions. Here is minimal example: mkdir crash
cd crash
wget https://github.com/pikepdf/pikepdf/files/9680822/web.tar.gz
tar -xvzf web.tar.gz
python3.9 -m venv venv
. ./venv/bin/activate
pip install uWSGI==2.0.20 z3c.rml==4.2.0 pikepdf==6.0.2 Django==4.1.1 six
cd web
uwsgi --master --plugin python39 --http :8000 --virtualenv ../venv/ --module web.wsgi --max-requests 1 Then open http://localhost:8000/ and press Ctrl+c to stop uwsgi (or press F5 cca 10 times until crashes). Uwsgi will crash in shutdown phase. |
Well... this will be fun. uwsgi is a process supervisor so it interferes with all normal debugging tools. :| valgrind as usual is helpful and better a real stack trace:
The corresponding allocation came from here:
...which is pybind11_meta_dealloc is responsible for cleaning up all C++ types registered with pybind11. It's likely this will turn out to be a pybind11 issue, although it may be related to the way that pikepdf monkeypatches its C++ class bindings. I think uwsgi may be at Note the caveats in Py_FinalizeEx - uwsgi's method of canceling interpreters is not guaranteed to work on all C extensions: My next step will be to try to find a minimal reproducible using pybind11 only. |
The error occurs if bind_vector/map is used, regardless of whether the macro |
Reproduced in a standalone project - this is a pybind11 issue. |
Hello, i have this set of packages:
This is my reportlab rml file rendered using z3c.rml:
code to render PDF:
Uwsgi runs with restricted number of requests like
--max-requests 1000
. This will restart worker after 1000 requests (mostly to prevent memory fragmentation).This causes segmentation fault in shutdown phase of uwsgi. After crash in this phase uwsgi cannot handle any new request. Here is backtrace:
The text was updated successfully, but these errors were encountered: