“context deadline exceeded” when converting Office files
Gotenberg gives every request 30 seconds, and the time a document spends waiting for LibreOffice counts. LibreOffice converts one document at a time, so when documents arrive together, or one takes long, a request runs out of time and Gotenberg answers 503. Raise the limit with --api-timeout, start LibreOffice with the container, and add containers when documents arrive together.
In Gotenberg’s log:
convert to PDF: supervisor run task: context deadline exceededIn the answer, from Gotenberg 8.34 on (503 Service Unavailable before):
The request exceeded the time limit. Increase it with --api-timeout, or reduce the workload.Thirty seconds, the wait included.
- The time limit covers the whole request.
--api-timeout, 30 seconds by default, counts the upload, the wait for LibreOffice, a restart and the conversion together. - LibreOffice converts one document at a time. Each container runs one LibreOffice. Documents that arrive together wait in line, and the last in line runs out of time first.
- Starts and restarts come out of the same 30 seconds. LibreOffice starts with the first request unless told to start with the container, and restarts after every 10 conversions by default.
- Some documents are slow. Large files, PDF/A output and fonts the image lacks make a conversion longer; too little CPU or memory makes every conversion longer.
- A few documents make LibreOffice hang. No time limit is long enough for those; newer Gotenberg images carry newer LibreOffice versions, which fixed some of them.
Raise the limit. Start LibreOffice early.
1. Give requests more time, and start LibreOffice with the container. In your compose file, add these lines to the gotenberg service:
gotenberg:
image: gotenberg/gotenberg:8
+ command:
+ - "gotenberg"
+ - "--api-timeout=120s"
+ - "--libreoffice-auto-start=true"
If the service has a command already, as Paperless-ngx’s has, add only the two lines that start with --. From Gotenberg 8.17 the same settings also work as the environment variables API_TIMEOUT and LIBREOFFICE_AUTO_START.
2. Start the service again with the new settings.
docker compose up -d3. When many documents arrive together, run more Gotenberg containers behind a load balancer, or give the container more CPU and memory. Install the fonts your documents use in the image.
No LibreOffice to wait for.
Marqius Kern answers Gotenberg’s API and reads Word, Excel and PowerPoint files itself, with no LibreOffice inside. It converts several documents at once, by default twice as many as the machine has processor cores, so a document does not wait behind another, and there is no office suite to start or restart.
In our test, 27 copies of a 41-page Word file sent at once to a machine with 4 processors: Gotenberg 8 with its defaults converted 16 and answered 503 for the other 11; with the fix above, it converted all 27, the last after 49 seconds. Marqius Kern, with its defaults, converted all 27 in about a second.
The switch is the image line, as for any Gotenberg setup, then the same command:
- image: gotenberg/gotenberg:8
+ image: marqius/kern
docker compose up -dIt takes the same flags and has the same time limit, --api-timeout, 30 seconds by default. It reads Word, Excel, PowerPoint, OpenDocument, RTF and CSV files; rarer formats, such as PowerPoint 97-2003, OpenDocument drawings and Visio, are refused with the reason.
Free for open source. Licensed for business.
Personal, teaching and open-source use is free with a Community licence, including open-source projects’ CI runs and documentation builds.
- Get your free key on marqius.com/licence/marqius-kern, then sign in with Google.
- Tick “I’ll use Marqius Kern only for personal, teaching or open-source work”.
- Get my free key, then Copy key.
- Set it as the variable
MARQIUS_LICENCEon your server.
Anything done by or for a business, including internal tools and client work, needs a paid licence. See the plans and prices.
Questions
What does “context deadline exceeded” mean in Gotenberg?
The request ran out of time. Gotenberg gives each request 30 seconds by default, the wait for LibreOffice included, and answers 503 when they are used up.
What is Gotenberg’s default timeout?
30 seconds, set by --api-timeout for the whole request. From Gotenberg 8.17 it can also be set with the API_TIMEOUT environment variable.
Why does it happen when several documents arrive at once?
Each Gotenberg container runs one LibreOffice, which converts one document at a time. The others wait in line, and their wait counts against the same 30 seconds.
Does a longer --api-timeout always fix it?
No. It helps when documents wait or convert slowly. A document that makes LibreOffice hang fails at any limit; a newer Gotenberg image, with a newer LibreOffice, fixed some of those.
Why does Paperless-ngx show 503 Service Unavailable?
Paperless-ngx waits up to 30 minutes for Gotenberg, so Gotenberg’s own 30 seconds run out first and Paperless-ngx shows its 503. Add --api-timeout to the command of its gotenberg service.
Does Marqius Kern have a time limit?
Yes, the same --api-timeout, 30 seconds by default. It reads Office files without LibreOffice and converts several at once, so documents do not wait in line behind one another.
Change one line. Keep your documents.
Compare your own documents side by side first, as the switching guide shows, then switch.