You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tobias Kremer <li...@funkreich.de> on 2008/07/01 09:42:51 UTC

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Quoting Perrin Harkins <pe...@elem.com>:
> On a closer look, you're not.  You are keeping around your $foo
> closure variable in handler(), as well as putting it in a global.
> It's not obvious why that causes this problem.  If you want to
> determine whether Apache::DBI is malfunctioning for you in some way,
> I'd suggest just removing it and seeing if the problem goes away.
> Your test app should work fine without it.

Removing Apache::DBI makes the errors go away. Using two different connection
strings for my initial connection during startup and the subsequent connections
in the handler() method also works. So everything looks like the connection made
during startup is indeed re-used somehow, although Apache::DBI correctly reports
that it won't cache it. Maybe now's the time to file a bug report ...

--Tobias

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Tobias Kremer <li...@funkreich.de>.
> I don't know the details, but there is something about the way
> PerlModule works in mod_perl 1 that causes it to load the module again
> when apache restarts at startup (it runs yours conf file twice when
> you start, as documented).  Using an explicit use() puts an entry in
> %INC and fixes the issue.  This should happen with require() as well,
> so I don't know what the problem is, but I've been told that mod_perl
> 2 doesn't have this problem.

So, due to this being the mod_perl list there must be somebody here who knows
what's going on deep down in the guts of the beast :)

> There seems to be an additional bug in either Apache::DBI or mod_perl
> 1, since $Apache::ServerStarting == 1 seems not to be true the second
> time through.  Can you have your Perl section print out the values of
> $Apache::ServerStarting and $Apache::ServerReStarting?

This gives me:

Apache::ServerStarting   = 1
Apache::ServerReStarting = 0

once(!) on server startup - no matter if I "use" my handler or load it via
PerlModule.

--Tobias

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Perrin Harkins <pe...@elem.com>.
On Wed, Jul 2, 2008 at 5:12 AM, Tobias Kremer <li...@funkreich.de> wrote:
> No more errors there either! :)

Great!

> I don't know anything about the internals but to me the mod_perl source looks
> like PerlModule is using "require" instead of "use" to load modules. I guess
> that is making the difference?

I don't know the details, but there is something about the way
PerlModule works in mod_perl 1 that causes it to load the module again
when apache restarts at startup (it runs yours conf file twice when
you start, as documented).  Using an explicit use() puts an entry in
%INC and fixes the issue.  This should happen with require() as well,
so I don't know what the problem is, but I've been told that mod_perl
2 doesn't have this problem.

There seems to be an additional bug in either Apache::DBI or mod_perl
1, since $Apache::ServerStarting == 1 seems not to be true the second
time through.  Can you have your Perl section print out the values of
$Apache::ServerStarting and $Apache::ServerReStarting?

- Perrin

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Tobias Kremer <li...@funkreich.de>.
Quoting Tobias Kremer <li...@funkreich.de>:
> Quoting Perrin Harkins <pe...@elem.com>:
> > How are you loading this?  With a PerlModule call?  Can you try
> > loading it from a Perl section like this?
> > <Perl>
> >   use MyModule;
> > </Perl>
> Wow, it seems that this fixes the problem!
> Do you have any idea what is going on? I'll check out how our real system
> behaves with this change.

No more errors there either! :)

I don't know anything about the internals but to me the mod_perl source looks
like PerlModule is using "require" instead of "use" to load modules. I guess
that is making the difference?

Whatever the cause is, I think it should be documented somewhere. I'd happily
provide a doc-patch for whatever documentation is suitable :)

--Tobias

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Tobias Kremer <li...@funkreich.de>.
Quoting Perrin Harkins <pe...@elem.com>:
> How are you loading this?  With a PerlModule call?  Can you try
> loading it from a Perl section like this?
> <Perl>
>   use MyModule;
> </Perl>

Wow, it seems that this fixes the problem! At least with my minimal application.

Here's the debug output which looks quite promising IMHO:

On server start:
----------------
8816 Apache::DBI skipping connection during server startup, read the docu !!
[rest is gone!]

On first request:
-----------------
8818 Apache::DBI push PerlCleanupHandler
8818 Apache::DBI need ping: yes
8818 Apache::DBI new connect to 'foo:bar'
8818 Apache::DBI PerlCleanupHandler

This comes up a couple of times for every new process and afterwards
changes to "already connected" which is exactly the behaviour I expected in the
first place.

Do you have any idea what is going on? I'll check out how our real system
behaves with this change.

Thanks a lot, Perrin!

--Tobias

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, Jul 1, 2008 at 10:08 AM, Tobias Kremer <li...@funkreich.de> wrote:
> On server start:
> ----------------
> 20097 Apache::DBI  skipping connection during server startup, read the docu !!
> 20097 Apache::DBI  push PerlCleanupHandler
> 20097 Apache::DBI  need ping: yes
> 20097 Apache::DBI  new connect to 'foo:bar...'
> 20097 Apache::DBI  disconnect (overloaded)

That looks like two different connect attempts.  The line following
the "skipping" part is a return, and then it must come back in later.

How are you loading this?  With a PerlModule call?  Can you try
loading it from a Perl section like this?

<Perl>
  use MyModule;
</Perl>

- Perrin

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Tobias Kremer <li...@funkreich.de>.
Quoting Perrin Harkins <pe...@elem.com>:
> Yes, but what does it tell you on the first connection AFTER startup?
> It should say whether it's making a new connection or not.

Here's the complete debug output which suggests that the connection during
startup is reused for the first request.

On server start:
----------------
20097 Apache::DBI  skipping connection during server startup, read the docu !!
20097 Apache::DBI  push PerlCleanupHandler
20097 Apache::DBI  need ping: yes
20097 Apache::DBI  new connect to 'foo:bar...'
20097 Apache::DBI  disconnect (overloaded)

On first request:
----------------
20099 Apache::DBI  need ping: yes
20099 Apache::DBI  already connected to 'foo:bar...'
20099 Apache::DBI  PerlCleanupHandler

--Tobias

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, Jul 1, 2008 at 9:56 AM, Tobias Kremer <li...@funkreich.de> wrote:
> Yes, I'm using the latest 1.07 release. I already had the debug flag on and it's
> correctly telling me that it's "skipping connection during server startup".

Yes, but what does it tell you on the first connection AFTER startup?
It should say whether it's making a new connection or not.

- Perrin

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Tobias Kremer <li...@funkreich.de>.
Quoting Perrin Harkins <pe...@elem.com>:
> Ok.  First, check that you're on the latest version.  Then, turn on
> the debug flag and see if it thinks it is reusing the startup
> connection or not.

Yes, I'm using the latest 1.07 release. I already had the debug flag on and it's
correctly telling me that it's "skipping connection during server startup".

--Tobias

Re: Lost connection to MySQL server during query (was "Segfault when connecting during Apache startup")

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, Jul 1, 2008 at 3:42 AM, Tobias Kremer <li...@funkreich.de> wrote:
> Removing Apache::DBI makes the errors go away.

Ok.  First, check that you're on the latest version.  Then, turn on
the debug flag and see if it thinks it is reusing the startup
connection or not.

- Perrin