mod_perl locking problem with Apache::Session

Discussion in 'Perl Misc' started by PerlGuy, Dec 30, 2007.

  1. PerlGuy

    PerlGuy Guest

    Solved this once years ago and completely forgot the solution. Here's
    the setup:

    mod_perl2, Apache 2, Apache::Session::MySQL, ModPerl::Registry, and
    Apache::DBI

    Each script uses Apache::Session::MySQL to get a session and or write
    back to the existing session. Apache::Session::Lock::MySQL issues
    locks to the database with a GET_LOCK and RELEASE_LOCK statement.
    Under normal circumstances there is no problem. However, if we double
    click a "submit" button on a Web page or in some other way get two of
    the Apache mod_perl processes to be making requests using the same
    session at the same time, then we get into a lock condition. MySQL
    database shows User Lock states for the processes that are stuck in a
    lock:

    SELECT GET_LOCK('Apache-Session-4a3a60b7ec332a2de29dd95081c4406a',
    3600)

    Essentially those apache processes are hosed since they keep a
    consistent DB connection with Apache::DBI

    The button must really be "double-clicked" quickly to get this
    effect. The first time a process is started and it grabs the lock.
    The process does not complete -- it's like it is interrupted. The
    second one makes any updates to the database. Only solution I've come
    up with so far is to modify the lock time in
    Apache::Session::Lock::MySQL down to something like 10 seconds which
    is still 10x longer than any script will ever take.

    What's the solution?
    PerlGuy, Dec 30, 2007
    #1
    1. Advertising

  2. PerlGuy

    PerlGuy Guest

    Chalk this one up as an FAQ:

    If you're getting lots of locked Apache2 processes under mod_perl2 and
    you just moved your code over from standard CGI's, you're probably
    getting a few warnings about variables not remaining shared.
    Essentially the problem is that closures are getting created by those
    variables not remaining shared and if any of those variables are
    related to a database connection then you get locked processes. Once
    I made a few adjustments to my code to remove the variable warnings,
    the locking issues went away too.


    On Dec 29 2007, 9:53 pm, PerlGuy <> wrote:
    > Solved this once years ago and completely forgot the solution.  Here's
    > the setup:
    >
    > mod_perl2, Apache 2, Apache::Session::MySQL, ModPerl::Registry, and
    > Apache::DBI
    >
    > Each script uses Apache::Session::MySQL to get a session and or write
    > back to the existing session.  Apache::Session::Lock::MySQL issues
    > locks to the database with a GET_LOCK and RELEASE_LOCK statement.
    > Under normal circumstances there is no problem.  However, if we double
    > click a "submit" button on a Web page or in some other way get two of
    > the Apache mod_perl processes to be making requests using the same
    > session at the same time, then we get into alockcondition.  MySQL
    > database shows UserLockstates for the processes that are stuck in alock:
    >
    > SELECT GET_LOCK('Apache-Session-4a3a60b7ec332a2de29dd95081c4406a',
    > 3600)
    >
    > Essentially those apache processes are hosed since they keep a
    > consistent DB connection with Apache::DBI
    >
    > The button must really be "double-clicked" quickly to get this
    > effect.  The first time a process is started and it grabs thelock.
    > The process does not complete -- it's like it is interrupted.  The
    > second one makes any updates to the database.  Only solution I've come
    > up with so far is to modify thelocktime in
    > Apache::Session::Lock::MySQL down to something like 10 seconds which
    > is still 10x longer than any script will ever take.
    >
    > What's the solution?
    PerlGuy, Jan 7, 2008
    #2
    1. Advertising

  3. PerlGuy

    Guest

    On Jan 7, 3:07 am, PerlGuy <> wrote:
    > Chalk this one up as an FAQ:
    >
    > If you're getting lots of locked Apache2 processes under mod_perl2 and
    > you just moved your code over from standard CGI's, you're probably
    > getting a few warnings about variables not remaining shared.
    > Essentially the problem is that closures are getting created by those
    > variables not remaining shared and if any of those variables are
    > related to a database connection then you get locked processes.  Once
    > I made a few adjustments to my code to remove the variable warnings,
    > the locking issues went away too.
    >
    > On Dec 29 2007, 9:53 pm, PerlGuy <> wrote:
    >


    If you are using Apache::Session::MySQL, why not directly go to MySQL.
    I believe that MySQL itself can handle lock/unlock things pretty well.
    there is no much need to have to use a module to handle sessions,
    especially with Database. The only real thing you need to do without
    such modules is to generate session_ids by yourself. For me, I will
    only consider using Apache::Session::File in Apache::Session::*
    families.. My two cents

    lihao(XC)
    , Jan 7, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    mod_perl / Apache problem

    David, Oct 10, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    141
    Tore Aursand
    Oct 11, 2003
  2. Selmar
    Replies:
    2
    Views:
    167
    krakle
    Jul 21, 2004
  3. Replies:
    2
    Views:
    434
    Big and Blue
    Jan 25, 2006
  4. Robert Jansen

    Apache/PHP 5.1.2/mod_perl Solaris 10 Problem

    Robert Jansen, Apr 6, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    228
    Jansen Robert
    Apr 7, 2006
  5. stratfan
    Replies:
    1
    Views:
    288
    stratfan
    Nov 19, 2007
Loading...

Share This Page