Re: Apache::Session::Postgres error

2001-01-17 Thread Dirk Lutzebaeck


Hi, I would just like to tune in here. I am using Apache::Session 1.53
also with postgres and have the problem that sessions are not closed
in any case. I am also using Embperl 1.3.0 but maintaining the session
variable on my own. The effect is that when apache is restarted
everything works fine but after some time (or heavy load) some
sessions start not to store modification anymore. This culminates
after a while into an usable system which needs a restart. The
application code needs very careful examination for closing the
session in all cases.

To find out if it is the application that is not closing the session
or if there is a problem in Apache::Session or in the database is very
hard to track down. I checked all the application code and using
vanilla Apache::Session::Store::Postgres with FOR UPDATE, ie. using
locks on the session table. I would appreciate any suggestion on how
to debug/find unclosed sessions on a high volume site. Eg. one could
work with timeouts, this is when a session is not closed after some
period of time a warning would be issued. This would help much to find
out who is not closing the session.

Regards,

Dirk





Re: Apache::Session::Postgres error

2001-01-16 Thread Edmund Mergl

Edmund Mergl wrote:
> 
> Todd Finney wrote:
> >
> > I'm using Apache::Session::Postgres to track sessions via
> > cookies.  When I access a page, the cookie is correctly
> > sent by the server, and accepted by the client.  However,
> > on the second request, I'm getting a 'Object does not exist
> > in data store' error.
> >
> > It looks like the session is not being stored in the
> > database, although I can't figure out why.  When running
> > postmaster -d 2, I get the following output:
> >
> 
> This problem has been reported several times.
> find below the explanation of Francis J. Lacoste
> from Sun, 17 Oct 1999.
> 
> Edmund
> 
> This is because the DBIStore insert the encoded session data as
> binary data. PostgreSQL doesn't like that. You have to modify
> Apache::Session::DBIStore (or better implement a PGStore)
> to uuencode the session data. You can use for that MIME::Base64
> or better yet
> 
> pack( "u*" ) and unpack ( "u*" ).
> 
> I have a Apache::Session::DBIUUStore that does just that
> and that I use for similar reason. I also added a last_update
> field to the table which tracks the last update to the session
> data. Email me if you want it. (Available on perl licensing terms)
> 
> Hope this helps.
> 



sorry, I forgot the email address: 
 
"Francis J. Lacoste" <[EMAIL PROTECTED]>


Edmund


-- 
http://www.edmund-mergl.de
fon: +49 700 edemergl



Re: Apache::Session::Postgres error

2001-01-16 Thread Jeffrey W. Baker

On Tue, 16 Jan 2001, Edmund Mergl wrote:

> Todd Finney wrote:
> >
> > I'm using Apache::Session::Postgres to track sessions via
> > cookies.  When I access a page, the cookie is correctly
> > sent by the server, and accepted by the client.  However,
> > on the second request, I'm getting a 'Object does not exist
> > in data store' error.
> >
> > It looks like the session is not being stored in the
> > database, although I can't figure out why.  When running
> > postmaster -d 2, I get the following output:
> >
>
>
> This problem has been reported several times.
> find below the explanation of Francis J. Lacoste
> from Sun, 17 Oct 1999.
>
> Edmund
>
>
>
> This is because the DBIStore insert the encoded session data as
> binary data. PostgreSQL doesn't like that. You have to modify
> Apache::Session::DBIStore (or better implement a PGStore)
> to uuencode the session data. You can use for that MIME::Base64
> or better yet
>
> pack( "u*" ) and unpack ( "u*" ).

That's not true anymore.  Apache::Session 1.5+ have UUE and MIME modules
for talking to Pg and other binary-averse backing stores.  UUE is
automatically selected when Pg is in use.

-jwb




Re: Apache::Session::Postgres error

2001-01-16 Thread Jeffrey W. Baker

On Tue, 16 Jan 2001, Todd Finney wrote:

> I'm using Apache::Session::Postgres to track sessions via
> cookies.  When I access a page, the cookie is correctly
> sent by the server, and accepted by the client.  However,
> on the second request, I'm getting a 'Object does not exist
> in data store' error.

Looks like it could be a transaction handling problem.  I'll have a look
tonight. -jwb

>
> It looks like the session is not being stored in the
> database, although I can't figure out why.  When running
> postmaster -d 2, I get the following output:
>
> started: host=localhost user=postgres database=sessions
> InitPostgres
> StartTransactionCommand
> query: begin
> ProcessUtility: begin
> CommitTransactionCommand
> StartTransactionCommand
> query:
>  INSERT INTO sessions (id, a_session)
> VALUES
> ('8efc89ae6006cfdfa24d12eba4019526','AwMBCiA4ZWZjODlhZTYwMD
> ZjZmRmYTI0ZDEyZWJhNDAxOTUyNlgLX3Nlc3Npb25faWRY
> ')
> ProcessQuery
> CommitTransactionCommand
> StartTransactionCommand
> query: rollback
> ProcessUtility: rollback
> CommitTransactionCommand
> StartTransactionCommand
> query: begin
> ProcessUtility: begin
> CommitTransactionCommand
> StartTransactionCommand
> query:
>  UPDATE sessions SET a_session =
> 'AwMAWA==
> ' WHERE id = NULL
> ProcessQuery
> CommitTransactionCommand
> StartTransactionCommand
> query: commit
> ProcessUtility: commit
> CommitTransactionCommand
> StartTransactionCommand
> query: begin
> ProcessUtility: begin
> CommitTransactionCommand
>
> It appears to be rolling back the insert transaction, but I
> don't know why.  The session does not appear in the
> database, and all subsequent requests fail.   I've tried
> undef'ing, untie'ing, and make_modified (and various
> combinations) on the hash, to no avail.
>
> The whole handler is below, in case you're interested.
>
> thanks,
> Todd
>
>
> package LocalSites::Session;
>
> use strict;
> use Apache::Constants qw( DECLINED);
> use Apache::Log;
> use Apache::Session::Postgres;
>
> sub handler {
>  my $r = shift;
>  my $log = $r->server->log();
>  my $session;
>  my $use_cookies = $r->dir_config->{'UseCookies'} || 0;
>
>  if ($use_cookies) {
>  $log->error("Session: Begin Transaction Using
> Cookies");
>  $session = $r->header_in('Cookie');
>  $session =~ s/SESSION_ID=(\w*)/$1/;
>  $log->error("Session: ID is $session");
>  } else {
>  $log->error("Session: Begin Transaction Using Path
> Info");
>  # Placeholder for code to extract SESSION_ID from
> the path
>  }
>  undef $session if ! $session;
>
>  my %session = ();
>  tie %session, 'Apache::Session::Postgres', $session, {
>  DataSource=>'dbi:Pg:dbname=sessions',
>  UserName=>'postgres',
>  Password=>'password',
>  Commit=>1
>  };
>  my $cookie = "SESSION_ID=".%session->{_session_id}.";
> domain=.dom.com; path=/;";
>  $r->header_out("Set-Cookie"=>$cookie ) if ! $session;
>  $r->pnotes('SESSION_ID', %session->{_session_id});
>  $r->pnotes('AUTH_LEVEL', %session->{auth_level} || 0
> );
>  $log->error("Session: ".%session->{_session_id});
>  untie(%session);
>  undef %session;
>  $log->error("Session: End Transaction");
>  return DECLINED;
> }
>
>




Re: Apache::Session::Postgres error

2001-01-16 Thread Todd Finney

At 01:28 PM 1/16/01, Edmund Mergl wrote:
>Todd Finney wrote:
> > It looks like the session is not being stored in the
> > database, although I can't figure out why.  When 
> running
> > postmaster -d 2, I get the following output:
> >
>
>This problem has been reported several times.
>find below the explanation of Francis J. Lacoste
>from Sun, 17 Oct 1999.

Yes, I saw that.  Francis was addressing the use of 
Apache::Session::DBI, however.  Since that time, JWB has 
released Apache::Session::Postgres and 
Apache::Session::Store::Postgres, the data store for the 
former.  I (perhaps incorrectly) assumed that he had 
implemented the correct conversion in this module.

Do I still need to do this conversion under the newer 
Apache::Session?

Todd





Re: Apache::Session::Postgres error

2001-01-16 Thread Edmund Mergl

Todd Finney wrote:
> 
> I'm using Apache::Session::Postgres to track sessions via
> cookies.  When I access a page, the cookie is correctly
> sent by the server, and accepted by the client.  However,
> on the second request, I'm getting a 'Object does not exist
> in data store' error.
> 
> It looks like the session is not being stored in the
> database, although I can't figure out why.  When running
> postmaster -d 2, I get the following output:
> 


This problem has been reported several times.
find below the explanation of Francis J. Lacoste
from Sun, 17 Oct 1999.

Edmund



This is because the DBIStore insert the encoded session data as
binary data. PostgreSQL doesn't like that. You have to modify
Apache::Session::DBIStore (or better implement a PGStore) 
to uuencode the session data. You can use for that MIME::Base64
or better yet

pack( "u*" ) and unpack ( "u*" ).

I have a Apache::Session::DBIUUStore that does just that
and that I use for similar reason. I also added a last_update
field to the table which tracks the last update to the session
data. Email me if you want it. (Available on perl licensing terms)

Hope this helps.




-- 
http://www.edmund-mergl.de
fon: +49 700 edemergl



Apache::Session::Postgres error

2001-01-16 Thread Todd Finney

I'm using Apache::Session::Postgres to track sessions via 
cookies.  When I access a page, the cookie is correctly 
sent by the server, and accepted by the client.  However, 
on the second request, I'm getting a 'Object does not exist 
in data store' error.

It looks like the session is not being stored in the 
database, although I can't figure out why.  When running 
postmaster -d 2, I get the following output:

started: host=localhost user=postgres database=sessions
InitPostgres
StartTransactionCommand
query: begin
ProcessUtility: begin
CommitTransactionCommand
StartTransactionCommand
query:
 INSERT INTO sessions (id, a_session) 
VALUES 
('8efc89ae6006cfdfa24d12eba4019526','AwMBCiA4ZWZjODlhZTYwMD
ZjZmRmYTI0ZDEyZWJhNDAxOTUyNlgLX3Nlc3Npb25faWRY
')
ProcessQuery
CommitTransactionCommand
StartTransactionCommand
query: rollback
ProcessUtility: rollback
CommitTransactionCommand
StartTransactionCommand
query: begin
ProcessUtility: begin
CommitTransactionCommand
StartTransactionCommand
query:
 UPDATE sessions SET a_session = 
'AwMAWA==
' WHERE id = NULL
ProcessQuery
CommitTransactionCommand
StartTransactionCommand
query: commit
ProcessUtility: commit
CommitTransactionCommand
StartTransactionCommand
query: begin
ProcessUtility: begin
CommitTransactionCommand

It appears to be rolling back the insert transaction, but I 
don't know why.  The session does not appear in the 
database, and all subsequent requests fail.   I've tried 
undef'ing, untie'ing, and make_modified (and various 
combinations) on the hash, to no avail.

The whole handler is below, in case you're interested.

thanks,
Todd


package LocalSites::Session;

use strict;
use Apache::Constants qw( DECLINED);
use Apache::Log;
use Apache::Session::Postgres;

sub handler {
 my $r = shift;
 my $log = $r->server->log();
 my $session;
 my $use_cookies = $r->dir_config->{'UseCookies'} || 0;

 if ($use_cookies) {
 $log->error("Session: Begin Transaction Using 
Cookies");
 $session = $r->header_in('Cookie');
 $session =~ s/SESSION_ID=(\w*)/$1/;
 $log->error("Session: ID is $session");
 } else {
 $log->error("Session: Begin Transaction Using Path 
Info");
 # Placeholder for code to extract SESSION_ID from 
the path
 }
 undef $session if ! $session;

 my %session = ();
 tie %session, 'Apache::Session::Postgres', $session, {
 DataSource=>'dbi:Pg:dbname=sessions',
 UserName=>'postgres',
 Password=>'password',
 Commit=>1
 };
 my $cookie = "SESSION_ID=".%session->{_session_id}."; 
domain=.dom.com; path=/;";
 $r->header_out("Set-Cookie"=>$cookie ) if ! $session;
 $r->pnotes('SESSION_ID', %session->{_session_id});
 $r->pnotes('AUTH_LEVEL', %session->{auth_level} || 0 
);
 $log->error("Session: ".%session->{_session_id});
 untie(%session);
 undef %session;
 $log->error("Session: End Transaction");
 return DECLINED;
}