Attempt to reload module.pm aborted.Compilation failed
Asked Answered
K

2

6

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.

Karaite answered 10/9, 2018 at 10:9 Comment(14)
@SteffenUllrich It does not have any syntax error, otherwise I wouldn't be able to run it. please read the question.Karaite
@SteffenUllrich, by the way, it is myModule; I just wrote a sample for my code, so I made a mistake here. On my code everything is ok. I have edited the question.Karaite
The convention for naming modules in Perl is to use camel case with the first letter being upper case, so it would be better to name this MyModule. I've looked at the Perl code you have on your github account. If you would like some feedback, feel free to post some of it on Code Review. :)Sharleensharlene
@SarahAziziyan: it is not clear what your myModule does. But maybe it does not return true in specific situations although it should do this when used within use ....Psychotomimetic
@Sharleensharlene yes sure, but that code is a sample. I have used Uppercase for my modules in my real code.Karaite
@SteffenUllrich what do you mean by thant? I will Edit the question and put the code of MyModule.pm .Karaite
A very important skill to learn in IT is to always say what you mean. Don't come up with examples that are like your problem. Come up with examples that are the same as your problem. If you change code to make it generic, make sure you use the same conventions and the same level of quality you always do. Being precise is very important, or it gets really hard to help because we don't understand you properly.Sharleensharlene
@SarahAziziyan: See also How to create a Minimal, Complete, and Verifiable example. It does not help if you show code which does not trigger the problem. If you try to show only what you think is the relevant part of the code in a simplified way you might actually omit the real cause.Psychotomimetic
@Sharleensharlene thank you for your advice. I have edited the question.Karaite
@SteffenUllrich I have posted my code and edited the question.Karaite
@SarahAziziyan: And there are no other messages in the web servers log file than the ones you've included in the question? Also, what do the modules PDBC, Request and Response actually do, i.e. failures in these modules might cause the problem too. And, could you please simplify your code as much as possible (while it should still trigger the problem) - I've already pointed out How to create a Minimal, Complete, and Verifiable example.Psychotomimetic
@SarahAziziyan: "This not All of it because I can't post it all. so I have edited it:" - and how do you know that the problem still exists with this edited version?Psychotomimetic
@SteffenUllrich sure I'll simplify it. (PDBC,Request and Response are others modules we have written and use here and in other codes)Karaite
@SteffenUllrich you say simplify it and then you say I should post all of it. what should I do? :)))Karaite
K
2

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.

Karaite answered 11/9, 2018 at 7:48 Comment(1)
Thank you for posting the solution you found :)Billingsley
R
2

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.

Regenerative answered 10/7, 2020 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.