Skip to content
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

(server) Qubes: Conversion of medium-sized documents fills up /tmp #574

Closed
Tracked by #413
apyrgio opened this issue Oct 4, 2023 · 2 comments
Closed
Tracked by #413

(server) Qubes: Conversion of medium-sized documents fills up /tmp #574

apyrgio opened this issue Oct 4, 2023 · 2 comments
Labels
bug Something isn't working P:Qubes QubesOS integration
Milestone

Comments

@apyrgio
Copy link
Contributor

apyrgio commented Oct 4, 2023

Problem

The Qubes converter currently handles /tmp in an inefficient way, leading to ENOSPC situations, when a document has more than 160 US letter pages.

Background

We have a known problem regarding the way we store pixel data in tmpfs (see #526), which becomes even worse in Qubes. The reason is that Qubes mounts tmpfs under /tmp this way:

tmpfs on /tmp type tmpfs (rw,size=1048576k,nr_inodes=35349,inode64)

The size of the /tmp dir in app and disposable qubes is therefore max 1GiB. At the same time, pdftoppm converts the pages at 150 DPI, which means each RGB page requires ~6.2MiB. Therefore, we can store at most ~165 pages in /tmp.

This limitation manifests both at the server-side, and at the client side. In the server-side, pdftoppm writes PPM files under /tmp/page*. We have a callback that writes the final RGB buffer to stdout and then removes the original PPM file, but these two processes are not synchronized, especially if the client-side does not catch up:

# Save pixel data
await self.write_page_data(data, rgb_filename)
# Delete the ppm file
os.remove(ppm_filename)
page_base = "/tmp/page"

In the client-side, we immediately write the received pixel data under /tmp/dangerzone, since this is where the pixels-to-pdf convert expects to find them:

untrusted_pixels = read_bytes(
self.proc.stdout,
num_pixels,
timeout=sw.remaining,
)
# Wrapper code
with open(f"/tmp/dangerzone/page-{page}.width", "w") as f_width:
f_width.write(str(width))
with open(f"/tmp/dangerzone/page-{page}.height", "w") as f_height:
f_height.write(str(height))
with open(f"/tmp/dangerzone/page-{page}.rgb", "wb") as f_rgb:
f_rgb.write(untrusted_pixels)

Solution

We don't have a solid solution yet. If we fix the client-side issue, by converting the RGB files to PNG immediately, then the disposable qube can still run out of space, if the client-side does not catch up (e.g., due to the conversion). We need a solution that fixes both sides.

@apyrgio apyrgio added P:Qubes QubesOS integration bug Something isn't working labels Oct 4, 2023
@apyrgio apyrgio added this to the 0.5.1 milestone Oct 4, 2023
@deeplow deeplow changed the title Qubes: Conversion of medium-sized documents fills up /tmp (server) Qubes: Conversion of medium-sized documents fills up /tmp Oct 24, 2023
deeplow added a commit that referenced this issue Nov 2, 2023
PDFtoPPM was producing RGB files faster than they were getting consumed.
Since the RGB files were only getting removed after they were sent, this
was leading to /tmp in the server getting clogged.

This solution consists in processing and sending images in chunks of 50
pages. This solution is slightly inneficient since it can't process and
send data simultaneously. That will be solved in a future commit.

Fixes #574
deeplow added a commit that referenced this issue Nov 2, 2023
PDFtoPPM was producing RGB files faster than they were getting consumed.
Since the RGB files were only getting removed after they were sent, this
was leading to /tmp in the server getting clogged.

This solution consists in processing and sending images in chunks of 50
pages. This solution is slightly inefficient since it can't process and
send data simultaneously. That will be solved in a future commit.

Fixes #574
@apyrgio apyrgio modified the milestones: Bookmarks, 0.6.0 Nov 22, 2023
@deeplow
Copy link
Contributor

deeplow commented Jan 24, 2024

I have confirmed now that with #627 the server doesn't run out of space. It does however still fail on the 164th page because we haven't yet addressed the client-side limitation #526. This will be easier anyways when we look at #625.

@apyrgio
Copy link
Contributor Author

apyrgio commented Feb 12, 2024

This has been resolved by fixing #443.

@apyrgio apyrgio closed this as completed Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P:Qubes QubesOS integration
Projects
None yet
Development

No branches or pull requests

2 participants