FAQ
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110329/567fecb2/attachment.htm

Search Discussions

  • Hernan Lopes at Mar 29, 2011 at 6:19 pm
    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 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@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110329/b83404f3/attachment.htm
  • Duncan Garland at Mar 30, 2011 at 8:40 am
    Thanks, but the script file has been rendered with the wrong information by that point so delaying execution wouldn't help.

    From: Hernan Lopes
    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 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@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/

    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110330/5b14c227/attachment.htm
  • Eden Cardim at Apr 11, 2011 at 6:49 pm
    "Duncan" == Duncan Garland 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/
  • Andrew Rodland at Mar 29, 2011 at 6:33 pm

    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
  • Duncan Garland at Mar 30, 2011 at 8:40 am
    Thanks. That's very useful and a bit depressing.

    -----Original Message-----
    From: Andrew Rodland
    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@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Kieren Diment at Mar 30, 2011 at 8:50 am
    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
    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@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/

    _______________________________________________
    List: Catalyst@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/
  • Larry Leszczynski at Mar 30, 2011 at 3:44 pm
    Hi Duncan -

    On Wed, 30 Mar 2011 09:40 +0100, "Duncan Garland"
    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
  • Duncan Garland at Mar 30, 2011 at 3:45 pm
    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
    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@lists.scsys.co.uk
    Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
    Dev site: http://dev.catalyst.perl.org/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMar 29, '11 at 5:46p
activeApr 11, '11 at 6:49p
posts9
users6
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase