You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Cory 'G' Watson <gp...@cafes.net> on 2003/08/15 16:02:47 UTC
Odd Reload Behavior
I've recently written some code that behaves in a way I don't
understand. It's basically a Handler that works for more than one
VirtualHost. For each VirtualHost that uses the Handler, a call is
made to App->loadPages(). It crawls an accompanying lib directory and
loads the pages into a hashref, which is then stored in a global hash
inside App.
Later, during requests, the Handler calls App->getPages("key"), where
key is a unique name for each virtual host. This _should_ return a
hashref full of page objects, but it returns undef.
Since the App module is pre-loaded (in startup.pl), and loadPages()
fills the hash, shouldn't the Handler's calls to getPages(key) work? I
know it can, because I had it working a couple weeks ago, but something
has broken it.
It looks as though this works during the first 'load' that Apache does,
which I'm assuming is the phase that checks for errors. The second
phase seems to cause my global hash to get undef'ed, even though the
loadPages() method works properly.
I can divulge more code if necessary, but perhaps someone can clue me
into why this happens.
Cory 'G' Watson
http://www.loggerithim.org
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Perrin Harkins <pe...@elem.com>.
On Sun, 2003-08-17 at 22:15, Cory 'G' Watson wrote:
> No, I only had a 'use App;' in my startup.
Your startup comes before the virtual host sections then?
> When I added a caller() to the top of my module, I saw the initial
> startup.pl use(), and then a later eval() that I couldn't track. When I
> turned OFF PerlFreshRestart, the order was reversed (eval() before
> startup.pl's use()) and my problem, of course, went away.
>
> I assumed from the beginning that this was something of my own doing, I
> just wanted to know why my ignorance was causing to happen. It seems that
> PerlFreshRestart causes some difference in the loading of my modules.
As I understand it, the only thing that PerlFreshRestart does is clear
%INC when you restart the sever (with a USR1 signal), kind of like this:
while (($k, $v) = each(%INC))
{
delete($INC{$k}); eval("require $k");
}
I don't know where that eval call would be coming from with PerlFreshRestart
off. That's why I was wondering if you had PerlModule call somewhere in
httpd.conf.
- Perrin
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Cory 'G' Watson <gp...@loggerithim.org>.
> On Sat, 2003-08-16 at 01:46, Cory 'G' Watson wrote:
> Well, first of all, you're just asking for trouble if you turn on
> PerlFreshRestart. Don't do it.
I forget why I added it. My (poor) memory seems to recall something from
the Eagle book causing me to add it. I'd never seen the 'evil' document
before this weekend. My Eagle book is at the office, and I don't recall
reading about it in the new Horse book.
> Do you hava anything like a PerlModule App in your httpd.conf? You
> haven't actually shown us your real conf, startup, or code, so I'm just
> guessing here.
No, I only had a 'use App;' in my startup.
> Are you no longer having problems now that you turned off
> PerlFreshRestart?
The problem has since gone away. I accidentally only replied to Ged
Haywood when I got the thing working.
When I added a caller() to the top of my module, I saw the initial
startup.pl use(), and then a later eval() that I couldn't track. When I
turned OFF PerlFreshRestart, the order was reversed (eval() before
startup.pl's use()) and my problem, of course, went away.
I assumed from the beginning that this was something of my own doing, I
just wanted to know why my ignorance was causing to happen. It seems that
PerlFreshRestart causes some difference in the loading of my modules.
--
Cory 'G' Watson
http://www.loggerithim.org
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Perrin Harkins <pe...@elem.com>.
On Sat, 2003-08-16 at 01:46, Cory 'G' Watson wrote:
> %somehash = ();
>
> This declaration is outside of any subroutines.
Okay, so your subs that refer to it are now closures. That could be
part of the issue. If you make %somehash a real global, it might help.
> I re-attacked this problem by adding a caller() check in App, and it
> proved to me that App was indeed being loaded twice. Once by my
> startup.pl (use App ();), and _again_ by an eval. caller() couldn't
> point me to the spot of code that was doing this, other than telling me
> it was a 'require App;'. I started flipping switches and localized it
> to PerlFreshRestart being on. When I turn it off, the eval() happens
> _before_ my startup.pl use() and subsequence call to App->load().
Well, first of all, you're just asking for trouble if you turn on
PerlFreshRestart. Don't do it.
Do you hava anything like a PerlModule App in your httpd.conf? You
haven't actually shown us your real conf, startup, or code, so I'm just
guessing here.
Are you no longer having problems now that you turned off
PerlFreshRestart?
- Perrin
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,
On Sat, 16 Aug 2003, Cory 'G' Watson wrote:
> started flipping switches and localized it to PerlFreshRestart being on.
Have you read
http://perl.apache.org/docs/1.0/guide/troubleshooting.html#Evil_things_might_happen_when_using_PerlFreshRestart
> When I turn it off, the eval() happens _before_ my startup.pl use()
> and subsequence call to App->load().
So is it working now?
73,
Ged.
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Cory 'G' Watson <gp...@loggerithim.org>.
On Friday, August 15, 2003, at 06:23 PM, Ged Haywood wrote:
>> Ignore syntax errors and lack of declarations, as I just threw that
>> together from memory
>
> The guesswork would be a lot easier if it didn't involve so much
> guesswork. :)
I think the root question of my email was lost in my poor explanation.
Basically, I have a module (which I called App) that has something like:
%somehash = ();
This declaration is outside of any subroutines. VirtualHosts then call
App->load("name", "libdir") to fille $somehash{$name} with a hashref of
page objects. All logging led me to believe that this variable was
being properly populated, but when that variable was accessed (via
getApp($name)), %somehash was undef.
Silly mistakes aside, I was basically trying to create a 'global'
variable that was populated by a method call _after_ it was
require()ed. The problem comes from the module being loaded _twice_.
The second time, %somehash = () sets things back to undef, but
loadApp() is not called again.
My motive for questioning the list was to find out if Apache's 'will
this survive a SIGHUP' pass caused this behavior, or if it was
something else I was missing.
I re-attacked this problem by adding a caller() check in App, and it
proved to me that App was indeed being loaded twice. Once by my
startup.pl (use App ();), and _again_ by an eval. caller() couldn't
point me to the spot of code that was doing this, other than telling me
it was a 'require App;'. I started flipping switches and localized it
to PerlFreshRestart being on. When I turn it off, the eval() happens
_before_ my startup.pl use() and subsequence call to App->load().
So this long-winded explanation is for the archives, and also to get an
idea as to why this happens. Thanks! :)
Cory 'G' Watson
Cory 'G' Watson
http://www.loggerithim.org
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hello again,
On Fri, 15 Aug 2003, Cory 'G' Watson wrote:
> PerlVar app blah
> <Perl>
> App->loadApp("blah", "/usr/local/blah/lib");
> </Perl>
> [snip]
> Ignore syntax errors and lack of declarations, as I just threw that
> together from memory
The guesswork would be a lot easier if it didn't involve so much guesswork. :)
Have you read
http://perl.apache.org/docs/1.0/guide/config.html#PerlSetVar_and_PerlAddVar
and
http://perl.apache.org/docs/1.0/guide/config.html#Apache_Configuration_in_Perl
?
73,
Ged.
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Cory 'G' Watson <gp...@cafes.net>.
On Friday, August 15, 2003, at 12:43 PM, Ged Haywood wrote:
> I'm not entirely convinced of the explanation, but have you tried
> testing the value of $Apache::Server::ReStarting in the code that
> fills the hash? It's in the Guide.
I'm not convinced of it either. :)
This code _would_ run twice, so I can protect it using the variable you
specified. I didn't know it existed. List messages seem to say that
this shouldn't be used?
> Your message was a bit cavalier about what's a hash and what's a
> hashref, are you sure you aren't just missing a dereference somewhere?
> Have you got 'use strict' and warnings on.
It's a difficult concept to relay without pasting a bunch of code.
-- App.pm:
package App;
my %pageobjs;
sub loadApp {
my $self = shift();
my $name = shift();
my $libdir = shift();
my %pages;
opendir(LIBDIR, $libdir);
while(there are files to check) {
# blah, if the file is a .pm, require and instantiate it into
$page
$pages{$pageObjectName} = $page;
closedir(LOBDIR);
$pageobjs{$name} = \%pages;
}
sub getPages {
my $self = shift();
my $name = shift();
return $pageobjs{$name};
}
-- startup.pl:
use App;
Sooo, using the above code, the VHost uses:
PerlVar app blah
<Perl>
App->loadApp("blah", "/usr/local/blah/lib");
</Perl>
And, inside the Handler:
my $app = $r->dir_config("app");
my $hashRefOfPageObjs = App->getPages($app);
And $hashRefOfPageObjs is always undef;
Ignore syntax errors and lack of declarations, as I just threw that
together from memory into the ol' MUA here. Does that make more sense?
I believe I had this working at one point, but something has caused it
go south. The double load I see (which you explained with your
Restarting tip) was suspect only because if I put code into App which
Data::Dumper's the hash, there is something in it, but it disappears
between the first load and the first request. It looks like <Perl>
sections are executed twice, but this shouldn't cause the variable to
go undefined.
Cory 'G' Watson
http://www.loggerithim.org
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: Odd Reload Behavior
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,
On Fri, 15 Aug 2003, Cory 'G' Watson wrote:
> It looks as though this works during the first 'load' that Apache does,
> which I'm assuming is the phase that checks for errors. The second
> phase seems to cause my global hash to get undef'ed, even though the
> loadPages() method works properly.
I'm not entirely convinced of the explanation, but have you tried
testing the value of $Apache::Server::ReStarting in the code that
fills the hash? It's in the Guide.
Your message was a bit cavalier about what's a hash and what's a
hashref, are you sure you aren't just missing a dereference somewhere?
Have you got 'use strict' and warnings on?
73,
Ged.
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html