[Zope] SESSION updates don't always take

Chris McDonough chrism at plope.com
Wed Mar 9 15:42:56 EST 2005


Your hunch is entirely correct.  This behavior is actually documented
within http://www.plope.com/Books/2_7Edition/Sessions.stx in the section
entitled "mutable data stored within session objects".  This isn't
really a general sessioning issue, it's more of a ZODB issue (which
sessions use "under the hood").

On Wed, 2005-03-09 at 15:40, Chris Kratz wrote:
> Hello all,
> 
> We have run into intermittent problems where the updates to items in the 
> SESSION object are not always saved.  
> 
> I've boiled the problem down to the following set of steps.
> 
> 1. The SESION object stores a list of items, in the test case, it is a list 
> with a single number.
> 2. We use a function to mutate that list directly by passing in a reference to 
> the list, ie function(SESSION['listName'])
> 3. The function makes changes to the list directly.
> 
> It seems that when a single user is using the system, this works consistently 
> about 99% of the time.  But, for some reason, when a second test case running 
> on a different machine/browser starts up, almost always we get an immediate 
> inconsistency between what should be in the session and what is actually 
> there in the first test case.  Now, it will happen running a solo version of 
> the test case as well, just far more rarely.  Note that running two test 
> cases inside of tabs in firefox will immediately become inconsistent because 
> they share the same session object within zope.  But running two browsers (ie 
> & firefox) or just using 2 different machines as the clients will trigger the 
> problem.
> 
> I also found that if I make any other unrelated change to the session object 
> using SESSION.set() it appears to fix the problem.  
> 
> My hunch is that by manipulating the list directly without using session.set, 
> we are causing a situation where sometimes the SESSION variable doesn't get 
> marked as dirty and saved.  Are there any other ideas out there why we would 
> be seeing the behavior we are seeing?
> 
> Thanks,
> 
> -Chris
> 
> Zope 2.7.3 on python 2.3.4 
> Linux kernel 2.6.8
> 
> **************************************************************************
> WARNING, this test case may stress the server it runs against due to 
> auto-reloading once per second.
> **************************************************************************
> 
> 1. Create DTML document by copying in the contents attached.
> 2. Create a python script with the contents attached.
> 3. View the page in two completely different browsers (to trigger separate 
> zope sessions)
> 4. The pages will run automatically reloading once a second and checking what 
> is in the session to what it thinks should be in the session.
> 
> I get an inconsistency within 50 runs on at least one of the browsers.  Often 
> within 10 runs one of them finds an inconsistency.
> 
> --------------  testSessionBug (DTML Doc) --------------
> <!-- initialize first time in -->
> <dtml-if numTests><dtml-else>
>    <dtml-call "REQUEST.set('numTests', 0)">
>    <dtml-call "SESSION.set('numTests', [0])">
> </dtml-if>
> 
> <html><head>
> </head><body>
> <h2><dtml-var title_or_id></h2>
> <p>
> 
> <dtml-if "SESSION.has_key('numTests') and numTests<>0 and 
> int(SESSION['numTests'][0])<>int(numTests)">
>    <b>Found Session List inconsistency</b>  <br>
> 
> 
>    SESSION=<dtml-var "SESSION['numTests'][0]"><br>
>    Should be=<dtml-var numTests>
> 
> <dtml-else>
>    <dtml-var numTests> complete without error.
>    <!-- Increment counter -->
>    <dtml-call "REQUEST.set('numTests', int(numTests)+1)">
> 
>    <!-- Write to SESSION -->
>    <dtml-call "writeToSession(REQUEST.SESSION['numTests'], numTests)">
> 
>    <!-- Update other variable, enable to keep from having a inconsistencies.  
> -->
>    <d-call "SESSION.set('test',1)">
>    
>    <!-- Javascript to reload page -->
>    <script Language="javascript">
>       setTimeout('self.location="testSessionBug?numTests=<dtml-var 
> numTests>"', 1000);
>    </script>
> </dtml-if> 
> 
> <br><br>
> <a href="testSessionBug">Start Over</a>
> 
> </p>
> </body></html>
> 
> --------------  writeToSession (python script) --------------
> ## Script (Python) "writeToSession"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=valList, val
> ##title=
> ##
> valList[0]=val



More information about the Zope mailing list