Bug 21092 - Bad template in patron card creator can cause server issues
Summary: Bad template in patron card creator can cause server issues
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Label/patron card printing (show other bugs)
Version: master
Hardware: All All
: P5 - low major (vote)
Assignee: Chris Nighswonger
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-19 15:30 UTC by Katrin Fischer
Modified: 2022-08-08 20:16 UTC (History)
2 users (show)

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


Attachments
Patron card layout (181.39 KB, image/jpeg)
2018-07-19 15:33 UTC, Katrin Fischer
Details
Patron card template (71.88 KB, image/jpeg)
2018-07-19 15:34 UTC, Katrin Fischer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Katrin Fischer 2018-07-19 15:30:03 UTC
While creating the PDF file for a patron card batch the CPU goes to 100% and brings the server down.

We have seen this behaviour in 2 separate package installations running 17.11.07 so far. We have sadly not been able to make it happen in a dev environment. 

Filing the report in hope that someone has an idea or seen something similar that will help us to nail down the problem.

So far we think the problem is related to 0 values in a patron card template. 

I will attach screenshots of the layout and patron card template used, when the problem appears.

To test:
- Add patron card template
- Add patron card layout (or use existing)
- Create batch of patrons
- Export
- Click on PDF link
- Boom! There is no error, the system just keeps loading.
Comment 1 Katrin Fischer 2018-07-19 15:33:22 UTC
Created attachment 77137 [details]
Patron card layout
Comment 2 Katrin Fischer 2018-07-19 15:34:18 UTC
Created attachment 77138 [details]
Patron card template

We are aware that the values make no sense - it's what you get when you save without changing anything on the form. The form doesn't require any fields, so that could happen by accident.
Comment 3 Chris Nighswonger 2018-07-19 15:49:23 UTC
(In reply to Katrin Fischer from comment #1)
> Created attachment 77137 [details]
> Patron card layout

It would be helpful to have the output of the following SELECT:

SELECT * FROM creator_layouts WHERE layout_id = <your id>\G
Comment 4 Chris Nighswonger 2018-07-19 15:49:58 UTC
(In reply to Katrin Fischer from comment #2)
> Created attachment 77138 [details]
> Patron card template
> 
> We are aware that the values make no sense - it's what you get when you save
> without changing anything on the form. The form doesn't require any fields,
> so that could happen by accident.

Likewise, the out put of:

SELECT * FROM creator_templates WHERE template_id = <your id>\G
Comment 5 Katrin Fischer 2018-07-19 16:28:14 UTC
Hi Chris,

was not sure how to report best, so I have created INSERTS of the data with workbench:

INSERT INTO `creator_layouts` (`layout_id`,`barcode_type`,`start_label`,`printing_type`,`layout_name`,`guidebox`,`oblique_title`,`font`,`font_size`,`units`,`callnum_split`,`text_justify`,`format_string`,`layout_xml`,`creator`) VALUES (20,'CODE39',1,'BAR','Testlayout',0,1,'TR',10,'POINT',0,'L','barcode','<opt page_side=\"F\" units=\"POINT\">\n  <images name=\"image_1\" Dx=\"72\" Ox=\"0\" Oy=\"0\" Sx=\"0\" Sy=\"0\" Tx=\"4.5\" Ty=\"63\">\n    <data_source image_name=\"none\" image_source=\"patronimages\" />\n  </images>\n  <text>&lt;firstname&gt; &lt;surname&gt;</text>\n  <text enable=\"1\" font=\"TR\" font_size=\"10\" llx=\"100\" lly=\"100\" text_alignment=\"L\" />\n  <text>Bibliothek: &lt;branchcode&gt;</text>\n  <text enable=\"1\" font=\"TR\" font_size=\"10\" llx=\"100\" lly=\"75\" text_alignment=\"L\" />\n  <text>Ablaufdatum: 31.06.2014</text>\n  <text font=\"TR\" font_size=\"6\" llx=\"115\" lly=\"65\" text_alignment=\"L\" />\n</opt>\n','Patroncards');


INSERT INTO `creator_templates` (`template_id`,`profile_id`,`template_code`,`template_desc`,`page_width`,`page_height`,`label_width`,`label_height`,`top_text_margin`,`left_text_margin`,`top_margin`,`left_margin`,`cols`,`rows`,`col_gap`,`row_gap`,`units`,`creator`) VALUES (24,0,'Testtemplate1','Default description',0,0,0,0,0,0,0,0,0,0,0,0,'POINT','Patroncards');
Comment 6 Katrin Fischer 2018-07-19 16:28:28 UTC
patronimages are activated.
Comment 7 Chris Nighswonger 2018-07-19 19:05:33 UTC
The INSERTS are great, and they represent the quickest way to duplicate a setup for testing.

I'll work on this over the next few weeks unless someone gets to it before me.
Comment 8 Katrin Fischer 2018-08-01 16:49:56 UTC
Thx! We haven't been able yet to narrow it down more, but it's a little scary. So would be nice to figure out what happens there.
Comment 9 Liz Rea 2022-08-08 19:15:29 UTC
This may be related to the line wrapping code? i.e. we get into a templated situation where we get into the while(1) loop and never get out. More recently lately we've seen the following in our logs when these fail (also this generates gigs and gigs of logs! It's terrible!)


[2022/08/08 11:28:39] [WARN] Use of uninitialized value $1 in quotemeta at /usr/share/koha/lib/C4/Patroncards/Patroncard.pm line 269.
[2022/08/08 11:28:39] [WARN] Use of uninitialized value $1 in quotemeta at /usr/share/koha/lib/C4/Patroncards/Patroncard.pm line 269.
[2022/08/08 11:28:39] [WARN] Use of uninitialized value $1 in concatenation (.) or string at /usr/share/koha/lib/C4/Patroncards/Patroncard.pm line 267.
[2022/08/08 11:28:39] [WARN] Use of uninitialized value $1 in concatenation (.) or string at /usr/share/koha/lib/C4/Patroncards/Patroncard.pm line 267.

Hope this helps some,
Liz
Comment 10 Chris Nighswonger 2022-08-08 20:16:19 UTC
(In reply to Liz Rea from comment #9)
> This may be related to the line wrapping code? i.e. we get into a templated
> situation where we get into the while(1) loop and never get out. More
> recently lately we've seen the following in our logs when these fail (also
> this generates gigs and gigs of logs! It's terrible!)

See my comment here:

https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31259#c6

The root problem may be the same.

An immediate solution would be to add a conditioned break to the loop that trips when the loop count exceeds the total length of the line being wrapped. That at least should prevent infinite looping.