----- Original Message ----- 
From: "Perrin Harkins" <[EMAIL PROTECTED]>
To: "Chris Ochs" <[EMAIL PROTECTED]>
Cc: "Modperl List" <[EMAIL PROTECTED]>
Sent: Monday, March 08, 2004 6:27 AM
Subject: Re: Apache::Session and DB_File problems


> On Sun, 2004-03-07 at 21:13, Chris Ochs wrote:
> > Been doing some more testing on this.   Previously I was untying the
> > sessions when the handler was finished.  But it seems that all it takes
is
> > just one child to exit uncleanly where I cant' catch the error and untie
the
> > sesssions, and that's all it takes to cause corruption.  If I untie the
> > session variables at the very start of the handler everything works
fine.
>
> What do you mean by untying the sessions?  Can you show us some code?
> All you should need to do is make sure the session object goes out of
> scope, which will happen even if your code dies.


Here is the start and end of the handler.   Also at the bottom is the code
that I use to create the session.

sub handler {
        $r = shift;
        untie %session;
        untie %basket;
        untie %cs;
        ...
       Do stuff here...

$myapp::template->process($req_file, $vars, $r) || return fail($r, OK,
$template->error);
        return success(OK);
    } # end handler

sub success {
   my ($status) = @_;
   $session{'timestamp'} = time if (defined %session);
   $basket{'timestamp'} = time if (defined %basket);
   $cs{'timestamp'} = time if (defined %cs);
   untie %session;
   untie %basket;
   untie %cs;
   $myapp::logger->debug("EndRequest");
   return $status;
   }

sub fail {
   my ($r, $status, $message) = @_;
   $session{'timestamp'} = time if (defined %session);
   $basket{'timestamp'} = time if (defined %basket);
   $cs{'timestamp'} = time if (defined %cs);
   untie %session;
   untie %basket;
   untie %cs;
   $myapp::logger->info("Error: $message");
   $params{'error_message'} = $message;
   my $vars = { req => $r, uri => $r->uri, env => \%ENV, params =>
\%params, };
   $Cart110::template->process("template_error.html", $vars, $r)
      || print "<h4><font color=red>Error:  </font>$message</h4>";
   $r->log_reason($message, $r->filename);
   $myapp::logger->debug("EndRequest (ERROR=$message)");
   return $status;
   }


Session code:
sub basket {
   my $dbfile = "$dbdir/$catalog" . "_basket.db";
   if ($params{'basket'}) {
      $session{'basket'} = $params{'basket'};
   }

   eval {
       tie %basket, 'Apache::Session::DB_File', $session{'basket'}, {
       FileName      => "$dbfile",
       LockDirectory => "$dbdir/lock",
       };
   };
   if ($@) {
       tie %basket, 'Apache::Session::DB_File', undef, {
       FileName      => "$dbfile",
       LockDirectory => "$dbdir/lock",
       };
   }
   $session{'basket'} = $basket{_session_id};
   $Cart110::logger->debug("BasketID = $basket{_session_id}");
}



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to