Skip to content

ETT-405 pdf download fixes#211

Draft
eumalin wants to merge 5 commits into
mainfrom
ETT-405-fixes
Draft

ETT-405 pdf download fixes#211
eumalin wants to merge 5 commits into
mainfrom
ETT-405-fixes

Conversation

@eumalin
Copy link
Copy Markdown
Contributor

@eumalin eumalin commented May 19, 2026

A follow up to #120, this is a bunch of short-term fixes to address the issue with downloading KU pdf files. The longer term fix will be to remove the jar from git and establish a java build workflow that follows the best practices.

Comment thread imgsrv/lib/SRV/Volume/PDF.pm Outdated
my $fh;

if ( ! $self->output_filename || SRV::Utils::under_server() ) {
if ( ! $self->output_filename || SRV::Utils::under_server() || $ENV{PSGI_COMMAND} ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eumalin I'd like to check this. I don't see the change specifically mentioned in the ticket history and I'd be hesitant to rely on this, since it potentially affects the handling of all PDF downloads, not just ku01. RV::Utils::under_server() returns ! defined $ENV{PSGI_COMMAND} so the second and third OR clauses essentially cancel. I would like to get rid of this and see if ku01 download still works.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work with the final OR clause removed. The output PDF file is empty, so I don't know if there is an error in the Java code, or if it is being provided a bad parameter. I have the contents of the temp config file for the Stamper being dumped into /htapps/moseshll.babel/cache/imgsrv/debug_out.txt so maybe the next step would be to see if the Java command can be run successfully with the given parameters. Unfortunately some of the files are ephemeral, in particular the source PDF which is in /ram

Copy link
Copy Markdown
Contributor Author

@eumalin eumalin May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, I get zero-byte pdf downloads; adding the condition fixes it. Seems to work ok for both KU and non KU pdf downloads.

I believe the empty PDF is not a Java error. It's a file overwrite. Java runs fine and writes the correct output. The problem is what happens after: Plack::App::Command always renames {cache_file}.download over {cache_file} at the end of the background process. Without the stream, Process::PDF writes Java's output directly to the cache path, then the rename overwrites it with the empty .download file.

The stream fix routes Java's output through the PSGI writer into .download first, so the rename produces the correct file. The reason _fill_params() sets output_filename to a string before _generate_coderef() runs is what breaks the original condition, ! $self->output_filename is already false by the time the check happens.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed the logic is awkward. I could replace the whole condition with an unconditional stream creation that forces streaming in the PSGI case and a comment explaining why, to avoid the confusion.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing it would also be awkward to change SRV::Volume::PDF behavior based on the Process subclass it is using. Ugh.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I don't think it's tied to the Process subclass. The streaming is now unconditional for all PDF downloads, KU or not.

I've simplified the fix: the condition is gone entirely and replaced with a comment. The original guard (! $self->output_filename) was meant to skip stream creation if a path was already set, but _fill_params() always sets output_filename to a string before _generate_coderef() runs, so the guard was never true in background mode anyway.

Also bumped the stamper to 1.1 (was 1.0-SNAPSHOT), updated stamp_pdf.pl and both pom files. Tests pass, but we need more coverage - it makes sense to me to do this as part of a follow up that will address the remaining issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants