You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mark Stosberg <ma...@summersault.com> on 2005/08/02 22:20:34 UTC

debugging 'server closed the connection unexpectedly' from PostgreSQL 8.0

Hello,

I'm debugging why I'm getting 'server closed the connection
unexpectedly' intermittently in a modperl application.

Unfortunately it has only been seen on the production server and not on
our development server making it harder to debug.

On the database side, nothing looks unusual in the load or the logs, so
I'm suspecting there is a fix on the modperl side.

I am using Apache::DBI, and have identified a couple of aspects which
might be "special" in this part of the application:

1. The db handle is being used inside of a Data::FormValidator
constraint. From what I've read, it seems possible that the handle is
suffering some "trapped in a closure" effect. However, we use constructs
like this throughout the site without a problem, so I doubt this is
where the issue is.

2. In a couple related modules we a construct like: "our $DBH = DBI->connect()". 
We don't do that elsewhere in the application. With some effort we could
refactor the code to get rid of this. I tried switching to "local our",
but I got a test failure. (Although I didn't get to the bottom of why
that test failed before reverting). 

Usually we pass the handle around through the CGI::Application object,
and that works fine. 

I'm interested to know: Does it seem like I am even looking in the right
place to troubleshoot this? General suggestions?  

    Mark


Re: debugging 'server closed the connection unexpectedly' from PostgreSQL 8.0

Posted by Michael Peters <mp...@plusthree.com>.
Mark Stosberg wrote:

> 2. In a couple related modules we a construct like: "our $DBH = DBI->connect()". 
> We don't do that elsewhere in the application. With some effort we could
> refactor the code to get rid of this. I tried switching to "local our",
> but I got a test failure. (Although I didn't get to the bottom of why
> that test failed before reverting). 

I don't know if this is the root of you problems, but this seems like a
bad idea anyway. Depending on how you do this and where, ff you preload
this module it will open the db connection at server startup (which
isn't bad in and of itself). That handle will have to be closed after
startup is done. DB handles opened before the children are forked cannot
be used after the fork.

> Usually we pass the handle around through the CGI::Application object,
> and that works fine. 

This seems like the better approach.

> I'm interested to know: Does it seem like I am even looking in the right
> place to troubleshoot this? General suggestions?

Is this a Pg or Apacahe error? Are you using Apache::DBI?

You might be ablet to reproduce the problem in your QA env if you run
the server in single process mode. This will make it easier to simulate
all of the children getting hit and serving requests.

-- 
Michael Peters
Developer
Plus Three, LP