Self-host PDF Generation Failed

When an order is submitted a background task is kicked off to generate a PDF export of the order and email it it to relevant parties.

The background task seems to randomly fail with the error, “PDF generation failed: Components did not load within allowed time.”

It works ~98% of the time and failed at a similar pace when using the Anvil hosted platform too. It’s now running on a 4core 8GB or RAM machine that is usually around 10% CPU utilization and 5-6 GB of RAM free. We’re using direct Postgresql DB access running on the same VM and the DB is lightning fast.

We have limited insight into the anvil-runtime under the hood to try to diagnose this issue further. Are there any other logs/details we could try to retrieve? It seems like the anvil-runtime is not taking full advantage of the number of cores and RAM that we have available, is there any way to modify that? Has the anvil-runtime project stagnated, there hasn’t been real updates in 10+ months. Since we were encountering this issue on the hosted version, it seems like our problem may be in the runtime itself.

Thank you

The rendering to pdf happens in a headless chrome, and it very likely use just one core.

There is a 30 second timeout. I haven’t played with the open source server, so I don’t know how to modify that.

This post may help you.

1 Like

This post was also inspired by the above link and cloning it will give you some hints how to work around the timeout.

2 Likes

This issue was encountered again today. I don’t think the problem is actually with our PDFRenderer code/logic, I think the server/run-time has an internal issue that is causing this. Today’s error, “error_from_server anvil._server.AnvilWrappedError: Exception: ‘PDF generation failed: Could not initialise printing service within allowed time.’”

However, at the same time, the server starts responding to users with this message:
image

The system has an average load of < 0.2 and usually has 5+ GB of free RAM available. I don’t see any abnormalities when the issue occurs in our netdata dashboard. The webserver still responds successfully (which is a mixed blessing as that prevents my error alert from being generated)…

Any advice from the Anvil Team? I know that this issue was happening when we were using the Anvil Platform and not self-hosting.

Thank you

1 Like