Update (Aug 02):I've edited my original post to include downloadable code and clarify the test case.

I have a Catalyst applications, which uses Catalyst::Model::KiokuDB (v0.12) with the CouchDB-backend. The applications leaks slightly for every request that access (not even use) the model. The controller (listed below) I'm using for reproducing this problem is simply calling $context->model() and then returns an empty reply, without ever using the model.

I've tracked it down to something related to Catalyst::Model::KiokuDB::save_scope(). Commenting out the call to save_scope() in ACCEPT_CONTEXT() removes the leak completely.

I've tried every single object and memory debug tool I know of, without any luck:

So now I have two questions for the collective wisdom of the PerlMonks:

  1. Does anyone have any ideas about what's going on?
  2. Does anyone have any ideas on how to debug this? Ideally I would like a tools or library, which can track every single malloc() call around this specific code block.

Steps to reproduce

  1. Create a new Catalyst application called TestApp:
    # catalyst.pl TestApp
  2. Place Leaktest.pm in TestApp/lib/TestApp/Controller:
    package TestApp::Controller::Leaktest; use strict; use warnings; use Moose; use utf8; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller' } sub index :Path :Args(0) { my ($self, $context) = @_; my $model = $context->model(); $c->response->body(""); $c->response->status(400); 1; } sub modules :Local { my( $self, $c, @path ) = @_; { no strict; # We're accessing $VERSION by symbolic reference no warnings 'uninitialized'; # The $VERSION might not be defin +ed $c->response->body(join "\n", map { s!/!::!g; # We're getting a file name.. +. s!.pm$!!; # ...and want a module name sprintf "%-80s %s", $_, ${"${_}::VERSIO +N"} } sort keys %INC); } $c->response->content_type("text/plain"); $c->stash->{current_view} = 'Nop'; 1; } sub exit :Local :Args(0) { exit(0); } 1;
  3. Place KiokuDB.pm in TestApp/lib/TestApp/Model:
    package TestApp::Model::KiokuDB; use Moose; BEGIN { extends 'Catalyst::Model::KiokuDB'; } __PACKAGE__->config( model_class => 'KiokuX::Model', model_args => { dsn => 'couchdb::uri=http://127.0.0.1:5984/lb-local', } ); 1;
  4. Place leaktest in TestApp/script:
    #!/bin/bash URL="http://localhost:3000/leaktest" EXIT="http://localhost:3000/leaktest/exit" APPNAME="testapp_server.pl" PID=$(pgrep -f ${APPNAME}) if [[ -z $PID ]]; then echo "Please start ${APPNAME} first!" exit 1; fi echo -e "HITS\tSZ\tRSS" echo -ne "0\t" ps -p ${PID} -o size,rss | sed -ne '2s/[ ]\+/\t/gp' for OUTER in $(seq 1 10); do for INNER in $(seq 1 1000); do ( curl $URL 2>&1) > /dev/null done echo -ne "$((${OUTER} * 1000))\t" ps -p ${PID} -o size,rss | sed -ne '2s/[ ]\+/\t/gp' done ( curl ${EXIT} 2>&1) > /dev/null
  5. Start TestApp in one console:
    # TestApp/script/testapp_server.pl
  6. Run leaktest in another console:
    # TestApp/script/leaktest

My modules

The following list was obtained from TestApp with
# curl -s http://localhost:3000/leaktest/modules | sed -ne '/.*\(Catalyst\|KiokuDB\).*[0-9\.]\+/p':

Catalyst + 5.80032 Catalyst::Action + -1, set by base.pm Catalyst::Action::RenderView + 0.16 Catalyst::Devel + 1.31 Catalyst::Model::KiokuDB + 0.12 Catalyst::Plugin::ConfigLoader + 0.30 Catalyst::Plugin::Static::Simple + 0.29 Catalyst::Runtime + 5.80032 KiokuDB + 0.52 KiokuDB::Backend::CouchDB + 0.10
I'll be happy to provide more details, but I was reluctant with posting the complete 449 lines long list.

In reply to Weird memory leak in Catalyst application using Catalyst::Model::KiokuDB by parmus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.