I'm looking at a very odd bug at the moment.  I haven't nailed
everything down 100%, but I'd really like to get another opinion...

In our site, we have an object which contains a file handle, talking to
a single threaded server.  The object needs to be destroyed in order to
free up the connection for the next object.

We are passing these objects as arguments into components.

   <& "/some/component", search => $myobj &>

I've recently upgraded one of our sites from Mason 1.28 to 1.33 and
discovered that these objects are not getting destroyed properly.  I
added some logging to the destructor and it was not being terminated at
the correct point.  Instead of going out of scope at the end of the
component which created the object, it's being destroyed at the end of
the request (or not all in some cases, which I don't understand).

A spot of debugging showed that $m->{stack} is holding on to the object
because it got passed as an argument.  The reason appears to be that
stack frames don't get popped off the stack any more, it's just that the
stack pointer gets decremented.  So the unused stack frames above the
stack pointer hang on to objects passed in arguments (in a seemingly
random fashion, although it's dependent on the order of component calls).

I've produced a patch (attached) which corrects this for my situation,
but it makes lots of tests fail.  I haven't looked at why yet.

I'm sorry, I haven't yet managed to produce a test case to replicate
this behavior.  It's next on my list.

Does any of this make sense?  Am I barking up the wrong tree?  Is this a
bug in Mason, or am I doing something stupid?

Many thanks,
-Dom

diff -ruN HTML-Mason-1.33.orig/lib/HTML/Mason/Request.pm 
HTML-Mason-1.33/lib/HTML/Mason/Request.pm
--- HTML-Mason-1.33.orig/lib/HTML/Mason/Request.pm      2006-05-28 
17:40:41.000000000 +0100
+++ HTML-Mason-1.33/lib/HTML/Mason/Request.pm   2006-09-21 10:50:19.505011147 
+0100
@@ -1217,6 +1217,7 @@
     my $flushable = exists $mods{flushable} ? $mods{flushable} : 1;
 
     # Add new stack frame and point dynamically scoped $self->{top_stack} at 
it.
+    local $self->{stack};
     local $self->{top_stack} = $self->{stack}->[$depth-1] =
         [
          $comp,           # STACK_COMP
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to