From b3517b980e1568e0eecbef1dae6e6f33eb07f898 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 21 Jan 2015 15:35:30 +0100 Subject: [PATCH] Bug 13606: Remove previous job data from the session Bug 11395 uses the session to store the report sent to the interface (update on biblio XX OK, etc.). If the session is stored in mysql, the max size of the sessions.a_session will be reached easily (TEXT field). To reproduce: 0/ Set SessionStorage to 'mysql' 1/ Create a file with 500 biblionumbers: mysql -e "select biblionumber from biblio limit 500;" | tail -n 500 > /tmp/biblionumbers.txt 2/ Define a marc modification template (something like "delete field 99$9" is nice) 3/ Load the /tmp/biblionumbers.txt in the batch biblio modification tool 4/ Repeat 3 You will get: Syck parser (line 1534, column 6): syntax error at /usr/lib/i386-linux-gnu/perl5/5.20/YAML/Syck.pm line 75. None Koha page is reachable. It comes from get_template_and_user > checkauth > get_session > l.1595 $session = new CGI::Session("driver:MySQL;serializer:yaml;id:md5", $sessionID, {Handle=>$dbh}); 5/ Get your sessionID contained in your CGISESSID cookie Have a look at the value a_session in the sessions table: mysql> select a_session from sessions where id="YOUR_SESSIONID"; You should see that the yaml is not correctly ended. The size of the DB field has been reached and the yaml is truncated. Test plan: 0/ Delete your CGISESSID cookie 1/ Try to reproduce the previous issue 2/ After the second batch, have a look at the sessions table and confirm that only one job_$JOB_ID exist in the yaml Signed-off-by: Mark Tompsett Confirmed that last completed run is the only thing in the session, under normal circumstances, now. This will go a long way to preventing the 16MB MEDIUMTEXT from filling up. --- C4/BackgroundJob.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/C4/BackgroundJob.pm b/C4/BackgroundJob.pm index 3ab5125..8487852 100644 --- a/C4/BackgroundJob.pm +++ b/C4/BackgroundJob.pm @@ -85,6 +85,19 @@ sub new { $self->{'jobID'} = Digest::MD5::md5_hex(Digest::MD5::md5_hex(time().{}.rand().{}.$$)); $self->{'extra_values'} = {}; + # Remove existing complete jobs + # not to explode the size of the session + my $prefix = "job_" . $self->{'jobID'}; + my $session = get_session($self->{'sessionID'}); + while ( my ( $param_name, $value ) = each %{$session->param_hashref} ) { + if ( $param_name =~ m|^job_| and $param_name ne $prefix ) { + my $old_job = $session->param($param_name); + if ( $old_job->{status} eq 'completed' ) { + $session->clear([ $param_name ]); + } + } + } + bless $self, $class; $self->_serialize(); -- 1.9.1