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
- example:
- 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?