mod_perl locking problem with Apache::Session

P

PerlGuy

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?
 
P

PerlGuy

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.
 
L

lihao0129

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.

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top