PDFPipe

It will not run

Renders crash under concurrency in a container

Single renders work. Two or three at once crash, with a tab-closed error or a plain crash. It never reproduces locally, where there is no container.

What is actually happening

Docker gives a container 64MB of shared memory by default, and a browser uses shared memory heavily for its renderer processes. One tab fits. Several do not, and the failure looks like a crash rather than like a resource limit.

Confirming it is this and not something that looks like it

Raise the shared memory size and try the same concurrency. If it stops crashing, that was it, and no amount of code change would have found it.

The fix

Raise the shared memory allocation for the container, or disable the browser's use of it, which trades some performance for not crashing. Both are container-level changes rather than application changes, which is why this one is hard to find from inside the application.

bash
# 64MB is the default and it is not enough for concurrent renders.
docker run --shm-size=1g my-app

# Or in compose:
#   services:
#     app:
#       shm_size: 1gb

If that was not it

These produce the same symptom often enough to be worth ruling out before assuming the fix above did not work.

  • --disable-dev-shm-usage as the alternative, which moves the scratch space to disk
  • Kubernetes, where the fix is an emptyDir volume with medium: Memory mounted at /dev/shm
  • Memory limits that make the shared memory increase impossible to satisfy
  • Concurrency that only reaches the threshold in production, which is why it passes CI

Frequently asked

Does this happen with every rendering engine?

The behaviour behind it is not specific to one tool. Docker gives a container 64MB of shared memory by default, and a browser uses shared memory heavily for its renderer processes. Anything rendering HTML to a paged medium has to make the same decision, so the fix travels with you if you change how the render happens.

Will this show up as an error in my logs?

Yes, this one surfaces as a thrown error or a failed status, which is why it is at least findable. The harder half is that the message often names the call that was in flight rather than the thing that actually failed.

Related failures

Problems people arrive at from the same starting point, or mistake for this one.

Paste your markup and see the rendered document, without signing up.