[cgiapp] CAP::Session causing errors under FastCGI and Plack?

Jason Crome cromedome at gmail.com
Tue Apr 3 23:51:34 EDT 2012


I keep banging my head against the wall trying to figure this out.  I expect that I am doing something else wrong, but whenever I comment out the session initialization logic, my app runs (as well as it can without sessions, that is).

I am getting this error under FCGI and PSGI:
"[Dispatch] ERROR for request '/': Unknown error: Error executing class callback in init stage: Calling session_config after the session has already been created at /Users/crome/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/CGI/Application/Plugin/Session.pm line 79."

In both cases, nginx is serving as the front end for FCGI::Engine or plackup (tried several engines).  

My cgiapp_init() looks like:

method cgiapp_init {
    my $system = $self->param( 'DEVNET_SYSTEM' );
    my $path   = $self->param( 'DEVNET_PATH'   );
    my $file   = "${path}conf/wedge.conf";

    $self->conf->init(
        file   => $file,
        driver => 'ConfigGeneral',
    );

    # Set up templating options and filters
    use DEVNET::TT qw( :all );
    my $tt_opts = {
        PRE_PROCESS   => 'devnet.tt',
        WRAPPER       => 'wrapper.tt',
        COMPILE_EXT   => '.ttc',
        COMPILE_DIR   => File::Spec->tmpdir . '/tt',
    };

    $tt_opts->{ CONTEXT } = Template::Timer->new( $tt_opts ) if $self->conf->param( 'debug' );

    $self->tt_config( TEMPLATE_OPTIONS => $tt_opts );

    mkdir "$path/logs" unless -e "$path/logs";
    $self->log_config( LOG_DISPATCH_MODULES => [{
        module         => 'Log::Dispatch::File',
        name           => 'Application',
        min_level      => $self->conf->param( 'DebugInfo' )->{ 'min_level' },
        filename       => "${path}logs/wedge.log",
        mode           => 'append',
        append_newline => 1,
    }]);

    try {
        $self->dbic_config( 'Property', {
            schema       => 'DEVNET::Schema',
            connect_info => [{ dbh_maker => sub {
                return DEVNET::DB::connect({
                    config => \%{ $self->conf->raw },
                });
            }}]
        });
	}
	catch {
		return $self->redirect( '/wedge/error/maintenance' );
	};

    mkdir "${path}data" unless -e "${path}data";
    $self->session_config(
        CGI_SESSION_OPTIONS => [ "driver:File", $self->query, { Directory => "${path}data/" }],
        SEND_COOKIE => 1,
    );
}

My nginx.conf looks like:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include           /DEVNET_WWW/nginx/conf/mime.types;
    default_type      application/octet-stream;
    sendfile          on;
    keepalive_timeout 65;
    gzip              on;

    server {
        listen       8000;
        server_name  localhost;

		access_log /DEVNET_WWW/Apps/sites/client/logs/access.log;
		error_log  /DEVNET_WWW/Apps/sites/client/logs/error.log;

		root /DEVNET_WWW/Apps/sites/client/static;

        location /common/ {
			alias /DEVNET_WWW/Apps/sites/default/common/;
        }

		location /wedge {
			include       /DEVNET_WWW/nginx/conf/fastcgi_params;
			fastcgi_pass  unix:/tmp/client.sock;

			fastcgi_split_path_info ^(/wedge)(/?.+)$;
			fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
			fastcgi_param PATH_INFO       $fastcgi_path_info;
			fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
			fastcgi_param DEVNET_PATH     /DEVNET_WWW/Apps/sites/client/;
			fastcgi_param DEVNET_ROOT     /DEVNET_WWW/Apps/;
			fastcgi_param DEVNET_SYSTEM   TaxInquiry;
		}
    }
}

Who else is using CAP::Session with FCGI or Plack?  How did you get it to work?  (Running on OS X but I am not sure that makes a difference).

Any help or suggestions most appreciated.  Thank you!

Jason A. Crome / CromeDome
DEVNET, Inc. - Cutting Edge Property Tax and Appraisal Solutions - http://www.devnetinc.com
--
AIM: TheOneCromeDome
Twitter: http://www.twitter.com/cromedome
Blog: http://crome-plated.tumblr.com/
CPAN: http://search.cpan.org/~cromedome/
github: http://github.com/cromedome
Bitbucket: https://bitbucket.org/cromedome/



More information about the cgiapp mailing list