Bug 37978 - Plack causes Internal server error in upload-cover-image.pl
Summary: Plack causes Internal server error in upload-cover-image.pl
Status: UNCONFIRMED
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: 24.05
Hardware: All All
: P3 normal
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-21 10:22 UTC by Manos PETRIDIS
Modified: 2024-11-06 13:47 UTC (History)
6 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
intranet-error.log (6.35 KB, text/plain)
2024-09-21 10:22 UTC, Manos PETRIDIS
Details
plack-intranet-error.log (312 bytes, text/plain)
2024-09-21 10:25 UTC, Manos PETRIDIS
Details
intranet-error.log (5.79 KB, text/plain)
2024-09-23 07:21 UTC, Manos PETRIDIS
Details
plack-intranet-error.log (1.13 KB, text/plain)
2024-09-23 07:22 UTC, Manos PETRIDIS
Details
intranet-access.log (32.08 KB, text/plain)
2024-10-01 06:05 UTC, Manos PETRIDIS
Details
intranet-error.log (42.88 KB, text/plain)
2024-10-01 06:06 UTC, Manos PETRIDIS
Details
plack.log (41.86 KB, text/plain)
2024-10-01 06:06 UTC, Manos PETRIDIS
Details
plack-intranet-error.log (4.68 KB, text/plain)
2024-10-01 06:07 UTC, Manos PETRIDIS
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Manos PETRIDIS 2024-09-21 10:22:48 UTC
Created attachment 171845 [details]
intranet-error.log

Error "Internal Server Error" is raised/shown on screen when one tries to upload local cover image in a new (migrated to a new server) koha installation. 

Relevant log contents attached.
Comment 1 Manos PETRIDIS 2024-09-21 10:25:09 UTC
Created attachment 171846 [details]
plack-intranet-error.log
Comment 2 Manos PETRIDIS 2024-09-23 07:21:52 UTC
Created attachment 171868 [details]
intranet-error.log
Comment 3 Manos PETRIDIS 2024-09-23 07:22:37 UTC
Created attachment 171869 [details]
plack-intranet-error.log
Comment 4 Manos PETRIDIS 2024-10-01 06:05:26 UTC
Created attachment 172243 [details]
intranet-access.log
Comment 5 Manos PETRIDIS 2024-10-01 06:06:07 UTC
Created attachment 172244 [details]
intranet-error.log
Comment 6 Manos PETRIDIS 2024-10-01 06:06:34 UTC
Created attachment 172245 [details]
plack.log
Comment 7 Manos PETRIDIS 2024-10-01 06:07:04 UTC
Created attachment 172246 [details]
plack-intranet-error.log
Comment 8 Manos PETRIDIS 2024-10-08 17:43:12 UTC
I noticed multiple error lines mentioning Middleware/CSRF.pm in error logs. 
Having disabled Plack, error no longer appears.
Comment 9 David Cook 2024-10-09 03:16:04 UTC
I'm not going to review these logs, but this issue does sound familiar. I may have fixed this locally. 

I've got a big backlog after being away from work for a while, but keeping this one on my radar.
Comment 10 Victor Grousset/tuxayo 2024-10-09 23:43:56 UTC
> Middleware/CSRF.pm in error logs. 

The timestamps of the errors don't seem relevant.

It might just a bot/crawler scanning webserver and having found your koha instance and making these weird CONNECT request. That are blocked early and verbosely since Bug 36863


Anyway, the suspicious things might rather be these 

> [Tue Oct 01 09:00:17.923588 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl: Use of uninitialized value $name in index at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 42., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:17.924077 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl: Use of uninitialized value $name in index at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 42., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:17.924283 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl: Use of uninitialized value $name in pattern match (m//) at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 45., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:17.924477 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl: Use of uninitialized value $name in hash element at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 45., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:17.924693 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl: Use of uninitialized value $pkg in concatenation (.) or string at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 53., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:17.924937 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl: Use of uninitialized value $name in concatenation (.) or string at /usr/lib/x86_64-linux-gnu/perl-base/Symbol.pm line 53., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:17.925119 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl:  not found: No such file or directory at /usr/lib/x86_64-linux-gnu/perl5/5.36/GD/Image.pm line 100., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image
> [Tue Oct 01 09:00:18.057414 2024] [cgi:error] [pid 3494:tid 3494] [client 192.168.1.254:58900] End of script output before headers: upload-cover-image.pl, referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image


Some missing config about the directory path for uploads?
In my koha-conf.xml i have
<upload_path>/var/lib/koha/kohadev/uploads</upload_path>

And switching from an old install without plack (if that's what happened) might lead to a different koha-conf.xml used and a wrong value for <upload_path>

In a Debian or Ubuntu Koha install via packages, I thing it's supposed to be in /etc/koha/sites/MY_KOHA_INSTANCE_NAME/koha-conf.xml
Comment 11 Manos PETRIDIS 2024-10-28 12:32:04 UTC
Thank you Victor, I had already added the entry in koha-conf.xml, and it points to a directory fully accessible by all, so this may not be the cause of the error. 

MP
Comment 12 Manos PETRIDIS 2024-10-28 13:43:47 UTC
Come to think of it though, it is an example of sloppy programming to introduce new stanzas in koha-conf.xml and not update existing installations with sane values of the newly introduced entries upon update.
Comment 13 Katrin Fischer 2024-10-28 13:50:26 UTC
(In reply to Manos PETRIDIS from comment #12)
> Come to think of it though, it is an example of sloppy programming to
> introduce new stanzas in koha-conf.xml and not update existing installations
> with sane values of the newly introduced entries upon update.

Do you want to provide a patch?
Comment 14 Manos PETRIDIS 2024-10-30 20:12:15 UTC
Funny thing, cover uploads worked just fine in my "old" koha installation before this new stanza was introduced. Do you want to provide an improved QA procedure?
Comment 15 David Cook 2024-10-30 22:24:06 UTC
(In reply to Manos PETRIDIS from comment #12)
> Come to think of it though, it is an example of sloppy programming to
> introduce new stanzas in koha-conf.xml and not update existing installations
> with sane values of the newly introduced entries upon update.

(In reply to Manos PETRIDIS from comment #14)
> Funny thing, cover uploads worked just fine in my "old" koha installation
> before this new stanza was introduced. Do you want to provide an improved QA
> procedure?

I'm not sure that being rude to people who volunteer their valuable time to develop and support Koha is the best way to get people to help you.

We already know that out-dated koha-conf.xml on upgraded installations is a problem. Consider bug 31059. If you can provide an idea for how to upgrade koha-conf.xml (or a related alternative) in a sensible and safe way during upgrade, feel free to add a comment on that bug report.
Comment 16 David Cook 2024-10-30 22:30:24 UTC
I've just tried uploading a local cover image in koha-testing-docker, and it's working fine. Given that and the lack of a test plan to reliably reproduce the error, I'm going to close this one. 

This sounds like a support problem. Consider one of the support options listed on https://koha-community.org/support/
Comment 17 Manos PETRIDIS 2024-10-30 23:13:18 UTC
What you're saying is: if it works in new installations, everything is fine. As if there are no previously existing koha installations. I know that being rude to people who volunteer their valuable time to develop and support Koha is not the best way to get people to help me; to help me and the myriad of people that have a running koha installation breaking on them on some odd, undocumented upgrade. 
I hadn't realised though that asking for better QA is rude. To be frank, my thoughts on been asked to provide a patch were "I may not know how to fix it, I do know however how not to break it in the first place". Can you really blame me? Please also note https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31180
Comment 18 David Cook 2024-10-30 23:25:42 UTC
(In reply to Manos PETRIDIS from comment #17)
> What you're saying is: if it works in new installations, everything is fine.
> As if there are no previously existing koha installations. I know that being
> rude to people who volunteer their valuable time to develop and support Koha
> is not the best way to get people to help me; to help me and the myriad of
> people that have a running koha installation breaking on them on some odd,
> undocumented upgrade. 
> I hadn't realised though that asking for better QA is rude. To be frank, my
> thoughts on been asked to provide a patch were "I may not know how to fix
> it, I do know however how not to break it in the first place". Can you
> really blame me? Please also note
> https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31180

Nope, that's not what I'm saying. I'm saying that Bugzilla is for reporting bugs and requesting enhancements, but this is more of a support query, so I've provided the options for support.

Yes, I can take issue with what you're saying. I'm not going to respond on this report again, as it sounds like we're not communicating well here, but I will take another look at the other one you've linked.
Comment 19 Jonathan Druart 2024-11-05 14:26:44 UTC
(In reply to Manos PETRIDIS from comment #12)
> Come to think of it though, it is an example of sloppy programming to
> introduce new stanzas in koha-conf.xml and not update existing installations
> with sane values of the newly introduced entries upon update.

Missing entries in koha-conf are highlighted on the about page.

After an upgrade a good practice is to check the "System information" tab of the about page (as well as running the search_for_inconsistencies.pl maintenance script).
Comment 20 Manos PETRIDIS 2024-11-05 17:44:29 UTC
Thanks for the pointers. Might I add though that 
a) I had visited the "System information" tab of the about page, and already had  added the missing entry in koha-conf.xml, as I mentioned in my comment of 2024-10-28 12:32:04 UTC.
b) Have just searched for "search_for_inconsistencies.pl" and google comes up with only two finds, both pointing to an IRC log of Jan 30th, 2020. Shouldn't it be mentioned in koha wiki somewhere?
c) the problem mentioned in the current bug report persists regardless of this specific koha-conf.xml entry. Furthemore, as already noted in my comment of 2024-10-08 17:43:12 UTC, I noticed multiple error lines mentioning Middleware/CSRF.pm in error logs posted. Having disabled Plack, error no longer appears.
Comment 21 Jonathan Druart 2024-11-06 13:45:00 UTC
You have a lot of those warnings:
Wide character (U+3B5) in substitution (s///) at /usr/lib/x86_64-linux-gnu/perl5/5.36/Template/Filters.pm

Does your filename only contain Greek characters? Can you try to rename the file with ASCII chars only?

This is the faral error: 
AH01215: stderr from /usr/share/koha/intranet/cgi-bin/tools/upload-cover-image.pl:  not found: No such file or directory at /usr/lib/x86_64-linux-gnu/perl5/5.36/GD/Image.pm line 100., referer: http://intra.atpf.gr:8080/cgi-bin/koha/tools/upload-cover-image.pl?itemnumber=3269&filetype=image

If still working, do you see the "Wide character" warnings?

If so to debug I would add a warn there:

Koha/UploadedFile.pm
115 sub file_handle {                                                                                     
116     my ( $self ) = @_;                                                                                
117     warn $self->full_path;
Comment 22 Jonathan Druart 2024-11-06 13:47:03 UTC
Also note that here we are using the 'tmp_path' config entry, not 'upload_path'.

If not present it will use File::Spec->tmpdir
https://metacpan.org/pod/File::Spec#tmpdir