On Thu, 29 Mar 2001, Victor Michael Blancas wrote:

> I'm using Apache::Session::Postgres with Apache::ASP.
> I'm getting a Segmentation Fault whenever I do a $dbh->disconnect at the
> end of the script.  When I comment out the the $dbh->disconnect however, I
> don't get any errors.  Having a script without a $dbh->disconnect at the
> end is wrong isn't it.  Anyone encountered this before?
> 
> I just tested it as a simple perl script on the command line. I'm still
> getting a core dumped Segmentation Fault whenever I do a disconnect at the
> end of the script.

I have had this happen to me as well.  You have to make sure that your
session is untied, before the database is disconnected.

What I found was that after pulling some data out of the session, it was
still TIE'ed to the session object.  

ie I with the following

my $userid = $session->{userid};

$userid is pointing into the tied hash, so if the database disappears, and
you try to access $userid, you will get a segfault.

The following program demonstrates this on my system


use strict;
use Apache::Session::Postgres ();
use DBI ();
 
my $dbh = DBI->connect('DBI:Pg:dbname=testdb', undef, undef, 
                        { RaiseError => 1, AutoCommit => 0 })
    or die "connect: Can't connect to database: $DBI::errstr";
 
tie my %s, 'Apache::Session::Postgres', undef, 
                        { 'Handle' => $dbh, 'Commit' => 1 };
 
# Put something in the session and then take it out again
$s{'testing'} = 'Something to put in the session';
my $test = $s{'testing'};

# disconnect from database
$dbh->disconnect;

# Accessing $test again will cause a segfault
print $test, "\n";


I realize that this is bad programming style, since I should untie %s
before I disconnect $dbh, and doing that stops the segfault (it also means
that $test will be blank if it is accessed after the untie).  But I don't
think that this should cause a segfault in the first place.

It sounds like there is a problem in Apache::Session::Postgres but I
haven't had time to search for it...

Cees Hek

Reply via email to