Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Force the session to be saved.

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


Duncan.Garland at motortrak

Mar 29, 2011, 10:46 AM

Post #1 of 9 (399 views)
Permalink
Force the session to be saved.

Hi,

We've been having some peculiar behaviour from our system. I think it's because the controller which produces the HTML page stores data in the session for retrieval by the controller which produces the associated javascript file.

The client begins processing the HTML page as soon as it starts to arrive. When it reaches the script tag it requests the javascript page. Occasionally the first controller hasn't written the session to the database when the javascript controller tries to retrieve it. (Catalyst::Plugin::Session::Store::DBIC).

I can move the script tag down the page a bit, but what I really need is a way to force the session to be written before the HTML template is rendered.

Something like:

$c->session->{javascript}->{$template} = { one = 1, two => 2};
$c->session->save;

Is there such a method?

Regards

Duncan


hernanlopes at gmail

Mar 29, 2011, 11:19 AM

Post #2 of 9 (386 views)
Permalink
Re: Force the session to be saved. [In reply to]

if your problem is delay javascript, or start script after any amount of
seconds try:
<script>
setTimeout( 'alertme();' , 1500 );
function alertme () {
alert(' time is up! ');
}
</script>

--Hernan

On Tue, Mar 29, 2011 at 2:46 PM, Duncan Garland <
Duncan.Garland [at] motortrak> wrote:

> Hi,
>
>
>
> We’ve been having some peculiar behaviour from our system. I think it’s
> because the controller which produces the HTML page stores data in the
> session for retrieval by the controller which produces the associated
> javascript file.
>
>
>
> The client begins processing the HTML page as soon as it starts to arrive.
> When it reaches the script tag it requests the javascript page. Occasionally
> the first controller hasn’t written the session to the database when the
> javascript controller tries to retrieve it.
> (Catalyst::Plugin::Session::Store::DBIC).
>
>
>
> I can move the script tag down the page a bit, but what I really need is a
> way to force the session to be written before the HTML template is rendered.
>
>
>
> Something like:
>
>
>
> $c->session->{javascript}->{$template} = { one = 1, two => 2};
>
> $c->session->save;
>
>
>
> Is there such a method?
>
>
>
> Regards
>
>
>
> Duncan
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>
>


andrew at cleverdomain

Mar 29, 2011, 11:33 AM

Post #3 of 9 (387 views)
Permalink
Re: Force the session to be saved. [In reply to]

On Tuesday, March 29, 2011 12:46:32 PM Duncan Garland wrote:
> Hi,
>
> We've been having some peculiar behaviour from our system. I think it's
> because the controller which produces the HTML page stores data in the
> session for retrieval by the controller which produces the associated
> javascript file.
>
> The client begins processing the HTML page as soon as it starts to arrive.
> When it reaches the script tag it requests the javascript page.
> Occasionally the first controller hasn't written the session to the
> database when the javascript controller tries to retrieve it.
> (Catalyst::Plugin::Session::Store::DBIC).
>
> I can move the script tag down the page a bit, but what I really need is a
> way to force the session to be written before the HTML template is
> rendered.
>
> Something like:
>
> $c->session->{javascript}->{$template} = { one = 1, two => 2};
> $c->session->save;
>
> Is there such a method?
>
> Regards
>
> Duncan

finalize_session (which writes the session to the DB) runs before
finalize_body (which writes the response to the client), so Catalyst already
does what you would like it to, and forcing a session write before running the
view is unlikely to help anything. I suspect either your database isn't
guaranteeing ordering, or the problem is somewhere other than where you're
looking.

Andrew

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


Duncan.Garland at motortrak

Mar 30, 2011, 1:40 AM

Post #4 of 9 (377 views)
Permalink
RE: Force the session to be saved. [In reply to]

Thanks, but the script file has been rendered with the wrong information by that point so delaying execution wouldn't help.

From: Hernan Lopes [mailto:hernanlopes [at] gmail]
Sent: 29 March 2011 19:19
To: The elegant MVC web framework
Subject: Re: [Catalyst] Force the session to be saved.

if your problem is delay javascript, or start script after any amount of seconds try:
<script>
setTimeout( 'alertme();' , 1500 );
function alertme () {
alert(' time is up! ');
}
</script>

--Hernan

On Tue, Mar 29, 2011 at 2:46 PM, Duncan Garland <Duncan.Garland [at] motortrak<mailto:Duncan.Garland [at] motortrak>> wrote:
Hi,

We've been having some peculiar behaviour from our system. I think it's because the controller which produces the HTML page stores data in the session for retrieval by the controller which produces the associated javascript file.

The client begins processing the HTML page as soon as it starts to arrive. When it reaches the script tag it requests the javascript page. Occasionally the first controller hasn't written the session to the database when the javascript controller tries to retrieve it. (Catalyst::Plugin::Session::Store::DBIC).

I can move the script tag down the page a bit, but what I really need is a way to force the session to be written before the HTML template is rendered.

Something like:

$c->session->{javascript}->{$template} = { one = 1, two => 2};
$c->session->save;

Is there such a method?

Regards

Duncan

_______________________________________________
List: Catalyst [at] lists<mailto:Catalyst [at] lists>
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


Duncan.Garland at motortrak

Mar 30, 2011, 1:40 AM

Post #5 of 9 (376 views)
Permalink
RE: Force the session to be saved. [In reply to]

Thanks. That's very useful and a bit depressing.

-----Original Message-----
From: Andrew Rodland [mailto:andrew [at] cleverdomain]
Sent: 29 March 2011 19:33
To: The elegant MVC web framework
Subject: Re: [Catalyst] Force the session to be saved.

On Tuesday, March 29, 2011 12:46:32 PM Duncan Garland wrote:
> Hi,
>
> We've been having some peculiar behaviour from our system. I think it's
> because the controller which produces the HTML page stores data in the
> session for retrieval by the controller which produces the associated
> javascript file.
>
> The client begins processing the HTML page as soon as it starts to arrive.
> When it reaches the script tag it requests the javascript page.
> Occasionally the first controller hasn't written the session to the
> database when the javascript controller tries to retrieve it.
> (Catalyst::Plugin::Session::Store::DBIC).
>
> I can move the script tag down the page a bit, but what I really need is a
> way to force the session to be written before the HTML template is
> rendered.
>
> Something like:
>
> $c->session->{javascript}->{$template} = { one = 1, two => 2};
> $c->session->save;
>
> Is there such a method?
>
> Regards
>
> Duncan

finalize_session (which writes the session to the DB) runs before
finalize_body (which writes the response to the client), so Catalyst already
does what you would like it to, and forcing a session write before running the
view is unlikely to help anything. I suspect either your database isn't
guaranteeing ordering, or the problem is somewhere other than where you're
looking.

Andrew

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


diment at gmail

Mar 30, 2011, 1:50 AM

Post #6 of 9 (375 views)
Permalink
Re: Force the session to be saved. [In reply to]

You can mess with the metaclass to do what you want, but I don't know how to do it myself I'm afraid.

On 30/03/2011, at 7:40 PM, Duncan Garland wrote:

> Thanks. That's very useful and a bit depressing.
>
> -----Original Message-----
> From: Andrew Rodland [mailto:andrew [at] cleverdomain]
> Sent: 29 March 2011 19:33
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Force the session to be saved.
>
> On Tuesday, March 29, 2011 12:46:32 PM Duncan Garland wrote:
>> Hi,
>>
>> We've been having some peculiar behaviour from our system. I think it's
>> because the controller which produces the HTML page stores data in the
>> session for retrieval by the controller which produces the associated
>> javascript file.
>>
>> The client begins processing the HTML page as soon as it starts to arrive.
>> When it reaches the script tag it requests the javascript page.
>> Occasionally the first controller hasn't written the session to the
>> database when the javascript controller tries to retrieve it.
>> (Catalyst::Plugin::Session::Store::DBIC).
>>
>> I can move the script tag down the page a bit, but what I really need is a
>> way to force the session to be written before the HTML template is
>> rendered.
>>
>> Something like:
>>
>> $c->session->{javascript}->{$template} = { one = 1, two => 2};
>> $c->session->save;
>>
>> Is there such a method?
>>
>> Regards
>>
>> Duncan
>
> finalize_session (which writes the session to the DB) runs before
> finalize_body (which writes the response to the client), so Catalyst already
> does what you would like it to, and forcing a session write before running the
> view is unlikely to help anything. I suspect either your database isn't
> guaranteeing ordering, or the problem is somewhere other than where you're
> looking.
>
> Andrew
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


larryl at emailplus

Mar 30, 2011, 8:44 AM

Post #7 of 9 (371 views)
Permalink
RE: Force the session to be saved. [In reply to]

Hi Duncan -

On Wed, 30 Mar 2011 09:40 +0100, "Duncan Garland"
<Duncan.Garland [at] motortrak> wrote:
> > finalize_session (which writes the session to the DB) runs before
> > finalize_body (which writes the response to the client), so Catalyst
> > already does what you would like it to, and forcing a session write
> > before running the view is unlikely to help anything. I suspect
> > either your database isn't guaranteeing ordering, or the problem is
> > somewhere other than where you're looking.
> >
> > Andrew
>
> Thanks. That's very useful and a bit depressing.

Is it possible you are seeing a race condition from other things being
loaded, maybe on the previous page? A one point we had a similar thing
going on and realized that some static content (images, etc.) was
actually going through the app and triggering a session read/save.


Thanks!
Larry

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


Duncan.Garland at motortrak

Mar 30, 2011, 8:45 AM

Post #8 of 9 (368 views)
Permalink
RE: Force the session to be saved. [In reply to]

Hi,

The sessions are in a standard Oracle table in which the primary key is the session id and the session data is a blob. The session should be retrieving the correct data. I think we'd have noticed long before now if the data wasn't be committed properly. (Autocommit is on anyway.)

Under the original setup we delete the key for the javascript template after using it (eg $c->session->{javascript}->{template1}). This morning I removed the delete statement. The problem still occurred.

I dug a bit more and it seems that the session occasionally completely loses its javascript key. (Same session id.)

I reduced the number of fastcgi processes from 5 to 1 and the problem went away.

This may mean that the race condition doesn't show up with one process.

However it may mean that the processes don't coordinate properly.

Should we have done something to make the session handling more sophisticated when we increased the number of fastcgi processes? For example do we have to do something explicit to lock a particular session to a particular process?

Regards

Duncan


-----Original Message-----
From: Andrew Rodland [mailto:andrew [at] cleverdomain]
Sent: 29 March 2011 19:33
To: The elegant MVC web framework
Subject: Re: [Catalyst] Force the session to be saved.

On Tuesday, March 29, 2011 12:46:32 PM Duncan Garland wrote:
> Hi,
>
> We've been having some peculiar behaviour from our system. I think it's
> because the controller which produces the HTML page stores data in the
> session for retrieval by the controller which produces the associated
> javascript file.
>
> The client begins processing the HTML page as soon as it starts to arrive.
> When it reaches the script tag it requests the javascript page.
> Occasionally the first controller hasn't written the session to the
> database when the javascript controller tries to retrieve it.
> (Catalyst::Plugin::Session::Store::DBIC).
>
> I can move the script tag down the page a bit, but what I really need is a
> way to force the session to be written before the HTML template is
> rendered.
>
> Something like:
>
> $c->session->{javascript}->{$template} = { one = 1, two => 2};
> $c->session->save;
>
> Is there such a method?
>
> Regards
>
> Duncan

finalize_session (which writes the session to the DB) runs before
finalize_body (which writes the response to the client), so Catalyst already
does what you would like it to, and forcing a session write before running the
view is unlikely to help anything. I suspect either your database isn't
guaranteeing ordering, or the problem is somewhere other than where you're
looking.

Andrew

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


edencardim at gmail

Apr 11, 2011, 11:49 AM

Post #9 of 9 (329 views)
Permalink
Re: Force the session to be saved. [In reply to]

>>>>> "Duncan" == Duncan Garland <Duncan.Garland [at] motortrak> writes:

Duncan> Thanks, but the script file has been rendered with the wrong
Duncan> information by that point so delaying execution wouldn’t
Duncan> help.

What exactly is the problem? You've speculated on sessions but you
haven't mentioned what the expected behaviour is and what you're getting
instead of that.

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://blog.edencardim.com/ http://www.shadowcat.co.uk/servers/

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.