Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to reload module.pm aborted.Compilation failed

Tags:

perl

mod-perl

I have a Perl script that is executing with mod_perl and works as an HTTP server. myServer.pl uses a module.pm. Everything looks fine when I use it with one user. but when I put it under pressure of hundreds of users it gives me this weird error.

[error] Attempt to reload MyModule.pm aborted.\nCompilation failed in require at /var/www/mod_perl/myServer.pl line 36.\nBEGIN failed--compilation aborted at /var/www/mod_perl/myServer.pl line 36.

Here is a sample of the beginning of my code for myServer.pl:

#!/usr/bin/perl -w
use strict;
use CGI;
#other use
use lib "/var/www/lib/receipt/pos";
use lib "/var/www/lib/common";
use MyModule;

my $q   = new CGI;
my $myM = new MyModule(requestParams=>$q);
if($myM){
  my $requestId = $myM->requestId;
  #do sth
}else{
    #do sth
}

#other codes

Edit

Here is a code for MyModule.pm

This not all of it because I can't post it all. so I have edited it:

package MyModule;
use strict;
use CGI;
use DBI;
use lib "/var/www/lib/common";
use lib "/var/www/lib/receipt/pos";
use PDBC;
use Request;
use Response;

use Log::Log4perl qw(get_logger);
my $Log4PerlConf_myLoggerP = q(
        log4perl.category.myLoggerP    = WARN, myLoggerPLogfile
        log4perl.appender.myLoggerPLogfile           = Log::Log4perl::Appender::File
        log4perl.appender.myLoggerPLogfile.filename  = /var/www/logs/myLoggerP.Log
        log4perl.appender.myLoggerPLogfile.layout = \
            Log::Log4perl::Layout::PatternLayout
        log4perl.appender.myLoggerPLogfile.layout.ConversionPattern = (%d) %L> %m %n
);
Log::Log4perl->init_once(\$Log4PerlConf_myLoggerP);
my $loggermyLoggerP = get_logger("myLoggerP");

use constant TRUE  => 1;
use constant FALSE => 0;

use constant D_VERSION  => "6.00";

my $myCode;
my $myMsg;

my $_init;


##-----------------------getter setters-----------------------------##
sub requestId       {$_[0]->{requestId}=$_[1]       if defined $_[1]; $_[0]->{requestId}}
sub requestParams   {$_[0]->{requestParams}=$_[1]   if defined $_[1]; $_[0]->{requestParams}}
sub reqID           {$_[0]->{reqID}=$_[1]           if defined $_[1]; $_[0]->{reqID}}
##--------------------end getter setters-----------------------------##

sub code {
    my ($self,$code) = @_;
    if (ref $self) { $self->{code}=$code if defined $code; return $self->{code} }
    else { $myCode=$code if defined $code; return $myCode; }
}

sub msg {
    my ($self,$msg) = @_;
    if (ref $self) { $self->{msg}=$msg if defined $msg; return $self->{msg} } 
    else {$myMsg=$msg if defined $msg; return $myMsg; }
}

sub new {
    my $class=shift;
    my $self={@_};
    bless $self,$class;
    if ($self->$_init) {
        return $self;
    } else {
        $myCode      = $self->code;
        $myMsg       = $self->msg;
    return FALSE;
    }
}

sub addToDB{
    my $self = shift;
    my $q    = shift;
    my $type = shift;

    my $database = new PDBC(name=>"schemaName");
    if($database){
        my $response = new Response(responseParams=>$q,database=>$database,type=>$type);
        if($response){
            $self->code(0);
            $self->msg("");
            return (0,"","");
        }else{
            $self->code(Response::code);
            $self->msg(Response::msg);
        }
    }else{
        $self->code(PDBC::code);
        $self->msg(PDBC::msg);
        $loggermyLoggerP->error("database connection error - code=".$self->code.",msg=".$self->msg);
    }
}

sub recoverLost{
    my $self = shift;
    my $line = "";

    for(my $i=0;$i<10;$i++){
        my $recordName = "record".$i;
        my $temp = $self->requestParams->param($recordName);
        if(defined($temp)){
            addToDB($temp,"recover");
        }else{
            last;
        }
    }
}

$_init = sub {
    my $self        = shift;
    my $code        = 0;
    my $msg         = "";
    my $farsiMsg    = "no error";    
    my $response;
    my $requestId   = "";
    $self->reqID(1);

    my $functionName   = $self->requestParams->param('functionName');

    if(defined $functionName){
        if($functionName eq "addToDB"){
            $self->addToDB($self->requestParams,"indirect");
        }
        elsif($functionName eq "recoverLost"){
            $self->recoverLost();
        }else{
            $self->code(1019);
            $self->msg("method undefined");
        }
    }else{
        $self->code(1019);
        $self->msg("method undefined");
    }

    if($self->code==0){     
        return TRUE;
    }else{
        return FALSE;
    }   

};

1;

This may have syntax errors, but it doesn't in my real code (this is a sample code I've edited the names and some other codes). It works except when hundreds of users send request at the same time it crashes.

like image 449
Sarah Aziziyan Avatar asked Sep 10 '18 10:09

Sarah Aziziyan


2 Answers

My problem has been solved. The Log::Log4perl module was causing this error. It was used in MyModule.pm. I have used it before (in other projects) without problems. but this time it seemed like it couldn't create a log file in the directory specified, although it didn't give me any errors in /var/log/httpd/error_log related to Log::Log4perl! sooooo annoying. I tried everything. and when I deleted Log::Log4perl from my project it worked without problem even under pressure of thousands of users.

For those who have the same issue: you have to look into your code and see if there are any other modules used in your code (this might be modules inside modules) that is not working properly.

like image 66
Sarah Aziziyan Avatar answered Oct 17 '22 01:10

Sarah Aziziyan


In an error case of "Attempt to reload Scalar/Util.pm aborted", the reason is finally found due to some dll is missing. When DBI.pm call "use Scalar::Util ();" and its dependances, it actually will need to load "\perl\site\lib\auto\List\Util\Util.xs.dll". Even process monitor will miss this dependence: it shows Perl want to load "\perl\site\lib\auto\List\Util\Util.ds". So the reload error message here is completely missleading, as well as the acompaning information on %INC or suggestions on using require or eval.

like image 2
Frank Avatar answered Oct 17 '22 02:10

Frank