MailSession sometimes could not be unserialized with REDIS
Hello,
I have a random error when I unserialize data from REDIS
[Tue Jun 28 09:45:37 2016] [error] Magic number checking on storable string failed at /usr/lib/perl/5.14/Storable.pm line 416, <GEN57> line 67009, at /usr/share/perl5/Apache/Session/Serialize/Base64.pm line 28\n
{code}
Our code try to get mail session from redis (see below)
Have you got any clue ?
Is it possible to have corrupted data in REDIS ?
And How can I avoid this problem ?
-- *** Our code
{code:perl}
sub sendConfirmationMail {
my ($self) = splice @_;
# Skip this step if user clicked on the confirmation link
return PE_OK if $self->{mail_token};
# Check if confirmation mail has already been sent
my $mail_session = $self->getMailSession( $self->{mail} );
{code}
-- /usr/share/perl5/Lemonldap/NG/Portal/_SMTP.pm
{code:perl}
## @method string getMailSession(string user)
# Check if a mail session exists
# @param user the value of the user key in session
# @return the first session id found or nothing if no session
sub getMailSession {
my ( $self, $user ) = splice @_;
my $moduleOptions = $self->{globalStorageOptions} || {};
$moduleOptions->{backend} = $self->{globalStorage};
my $module = "Lemonldap::NG::Common::Apache::Session";
# Search on mail sessions
my $sessions = $module->searchOn( $moduleOptions, "user", $user );
{code}
-- /usr/share/perl5/Lemonldap/NG/Common/Apache/Session.pm
{code:perl}
sub searchOn {
my ( $class, $args, $selectField, $value, @fields ) = splice @_;
my $backend = $args->{backend};
_load($backend);
if ( $backend->can('searchOn') ) {
return $backend->searchOn( $args, $selectField, $value, @fields );
{code}
-- /usr/share/perl5/Apache/Session/Browseable/Redis.pm
{code:perl}
sub searchOn {
my ( $class, $args, $selectField, $value, @fields ) = @_;
my %res = ();
my $index =
ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ];
if ( grep { $_ eq $selectField } @$index ) {
my $redisObj = Redis->new(%$args);
my @keys = $redisObj->smembers("${selectField}_$value");
foreach my $k (@keys) {
next unless ($k);
my $tmp = $redisObj->get($k);
next unless ($tmp);
$tmp = unserialize($tmp);
{code}
-- /usr/share/perl5/Apache/Session/Serialize/Base64.pm
{code:perl}
sub unserialize {
my $session = shift;
my $data = thaw(decode_base64($session->{serialized}));
die "Session could not be unserialized" unless defined $data;
#Storable can return undef or die for different errors
$session->{data} = $data;
}
{code}
-- /usr/lib/perl/5.14.2/Storable.pm
{code:perl}
#
# thaw
#
# Recreate objects in memory from an existing frozen image created
# by freeze. If the frozen image passed is undef, return undef.
#
sub thaw {
my ($frozen) = @_;
return undef unless defined $frozen;
my $self;
my $da = $@; # Could be from exception handler
eval { $self = mretrieve($frozen) }; # Call C routine
--> mretrieve