Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
lemonldap-ng
lemonldap-ng
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 244
    • Issues 244
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 2
    • Merge Requests 2
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • LemonLDAP NG
  • lemonldap-nglemonldap-ng
  • Issues
  • #2369

Closed
Open
Opened Nov 02, 2020 by Maxime Besson@maxbes🔧Maintainer

Memory leak in Issuer::_redirect

Concerned version

Version: 2.0.9

Platform: Nginx + FastCGI

Summary

  • Enable CAS issuer
  • Run a bench on any issuer endpoint without cookies
    • example: ab -c 10 -n 100000 http://auth.example.com/cas/login?service=http://somewhere
  • Watch memory going through the roof

Possible fixes

I tracked this memory leak down to the following code in Issuer.pm:

  # TODO: launch normal process with 'run' at the end
    return $self->p->do(
        $req,
        [
            'controlUrl',
            @{ $self->p->beforeAuth },
            $self->p->authProcess,
            @{ $self->p->betweenAuthAndData },
            $self->p->sessionData,
            @{ $self->p->afterData },
            $self->p->validSession,
            @{ $self->p->endAuth },
            (
                $restore
                ? sub {

                    # Restore urldc if auth doesn't need to dial with browser
                    $self->restoreRequest( $req, $ir );
                    $self->cleanPdata($req);
                    return $self->run( @_, @path );
                }
                : ()
            )
        ]
    );

Especially this part :


sub {
    # Restore urldc if auth doesn't need to dial with browser
    $self->restoreRequest( $req, $ir );
    $self->cleanPdata($req);
    return $self->run( @_, @path );
}

My theory is that using $req here creates a closure with a circular reference (since the sub is stored in $req->steps).

Whether or not my explanation is correct, the following fix appears to solve this leak:

sub {
    # Restore urldc if auth doesn't need to dial with browser
    $self->restoreRequest( $_[0], $ir );
    $self->cleanPdata($_[0]);
    return $self->run( @_, @path );
}

The test suite is happy with it too. OK for you @guimard? Is there a possibility that might change might break something?

Edited Nov 02, 2020 by Maxime Besson
Assignee
Assign to
2.0.10
Milestone
2.0.10 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: lemonldap-ng/lemonldap-ng#2369