[rt-devel] debug info on memory leaks under mod_perl.

Ruslan U. Zakirov cubic at acronis.ru
Mon Oct 20 11:41:51 EDT 2003


		Hello, RT hackers :)
	I want to remember to you that RT leaks.

	While my last hacking on RT I've understood that Perl and CPAN modules 
could be buggy too and at first time complain on them. But after 13 
hours of fighting with Apache::Leak, B::LexInfo, die 'Test', 
Data::Dumper and other similar shit I figured out that it's almost only 
RT problem.

	The problem is circular references.
Good article about it here:
http://www.perl.com/pub/a/2002/08/07/proxyobject.html

We leak at least one CurrentUser object + all object on which it has 
pointer(PrincipalObj, UserObj...) Why? Because of 'user' references on 
CurrentUser which have each object inherited from RT::Handle and 
RT::Record. And also CurrentObject itself have such pointer. So after 
untie of %session perl never call DESTROY on this objects.

1) weaken solution is good, but have issues
	a) perl should be >5.6.0, but it's not a problem for RT. RT have same 
requirments.
	b) such refs hardly maintainable in RT's OO scheme as I think.
2) emplimenting ProxyObject? I don't have expirience at all in it. 
Restless nights and of course I do it, but I'm not sure that Jesse apply 
  patches.(after digging with solution number 3 I think that this is 
good idea :) ).
3) write cleanup function that do all things. It's what I tried to do.
In RT::Interface::Web
sub CleanUp {
 
 

# we must cleanup objects in session
     $RT::Logger->debug("\%session address in CleanUp function: '" . 
\%session . "'");
     return unless(tied(%session));
     tied(%session)->save;
     $RT::Logger->debug("CleanUp func");
 
 

     foreach my $key (keys %session) {
         $RT::Logger->debug("Session key: '$key'");
         if (ref($session{$key}) && UNIVERSAL::can($session{$key}, 
'CleanUp')) {
                 $session{$key}->CleanUp();
         }
     }
 
 
                     }
Now we could use it in a component.
	Tried <%cleanup> block of Mason in autohandler. F... It's skipped if 
$m->abort() called. Only <%filter> block exec after abort, but it have 
another namespace so our 'local *session' forgoten :( F..k.

So need to implement call in component namespase that would be called 
latest. Doh... another problem is 'delete' calls. RT sometimes delete 
keys form %session :( so before deleting we should CleanUp value.

So with this function we should call it before aborts and deletes, but I 
think that it's wierd approach to solve problems.

4) Create RT::Session::* ISA Apache::Session::* and call cleanups on 
delete and destroy.

And other and other... What solution is our(or only Jesse :) ) choice? I 
don't have much expirience in systems design, so I like if you suggest 
something.

Uff... I hope you understand me. I know my english is terrible.
	Best regards. Ruslan.
PS:
And last. Jesse, I don't understand why RT::Init() call placed in 
RT::Mason::Handler? This cause another leak as I think, but I don't dig 
it deep. I only move this call upper just in RT::Mason and my test RT 
instalation feel fine for me.




More information about the Rt-devel mailing list