Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,949
    Plugin Contributions
    96

    Default Re: Duplicate Sessions

    Quote Originally Posted by mc12345678 View Post
    Pairs of numbers? Is that what is really present or was something mistyped when entered here?
    I'd imagine that niccol was posting both the Local and Master values.

  2. #12
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Duplicate Sessions

    Quote Originally Posted by lat9 View Post
    I'd imagine that niccol was posting both the Local and Master values.
    In that case, an update on my values for "consistency" would be:
    session.hash_bits_per_character 4 4
    session.hash_function 0 0

    Local first, master second.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #13
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Duplicate Sessions

    Yes, not caching the database is a solution. But comes with a seemingly small cost is performance. I didn't test extensively but the change was less than a few percent.

    still interested in the cause of this error though. It must come from the functions file sessions.php. In function _sess_write zen has:

    Code:
        $expiry = time() + $SESS_LIFE;
    
        $qid = "select count(*) as total
                from " . TABLE_SESSIONS . "
                where sesskey = '" . zen_db_input($key) . "'";
    
        $total = $db->Execute($qid);
    
        if ($total->fields['total'] > 0) {
          $sql = "update " . TABLE_SESSIONS . "
                  set expiry = '" . zen_db_input($expiry) . "', value = '" . zen_db_input($val) . "'
                  where sesskey = '" . zen_db_input($key) . "'";
    
          $result = $db->Execute($sql);
    
        } else {
          $sql = "insert into " . TABLE_SESSIONS . "
                  values ('" . zen_db_input($key) . "', '" . zen_db_input($expiry) . "', '" .
                           zen_db_input($val) . "')";
    
          $result = $db->Execute($sql);
    
        }
    Seems bizarre that this error can be created.

    If anyone has thoughts then I'd be interested :-)

  4. #14
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,949
    Plugin Contributions
    96

    Default Re: Duplicate Sessions

    Quote Originally Posted by niccol View Post
    Yes, not caching the database is a solution. But comes with a seemingly small cost is performance. I didn't test extensively but the change was less than a few percent.

    still interested in the cause of this error though. It must come from the functions file sessions.php. In function _sess_write zen has:

    Code:
        $expiry = time() + $SESS_LIFE;
    
        $qid = "select count(*) as total
                from " . TABLE_SESSIONS . "
                where sesskey = '" . zen_db_input($key) . "'";
    
        $total = $db->Execute($qid);
    
        if ($total->fields['total'] > 0) {
          $sql = "update " . TABLE_SESSIONS . "
                  set expiry = '" . zen_db_input($expiry) . "', value = '" . zen_db_input($val) . "'
                  where sesskey = '" . zen_db_input($key) . "'";
    
          $result = $db->Execute($sql);
    
        } else {
          $sql = "insert into " . TABLE_SESSIONS . "
                  values ('" . zen_db_input($key) . "', '" . zen_db_input($expiry) . "', '" .
                           zen_db_input($val) . "')";
    
          $result = $db->Execute($sql);
    
        }
    Seems bizarre that this error can be created.

    If anyone has thoughts then I'd be interested :-)
    lhungil pointed out a couple of posts back that it's most likely a race condition on busy stores (the check/optional insert is not atomic). Perhaps that section could be made atomic without changing the functionality as:
    Code:
     $expiry = time() + $SESS_LIFE;
     $sql = "insert IGNORE into " . TABLE_SESSIONS . "
               values ('" . zen_db_input($key) . "', '" . zen_db_input($expiry) . "', '" . zen_db_input($val) . "')";
    
     $db->Execute($sql);
    
     $sql = "update " . TABLE_SESSIONS . "
               set expiry = '" . zen_db_input($expiry) . "', value = '" . zen_db_input($val) . "'
               where sesskey = '" . zen_db_input($key) . "'";
    
     $result = $db->Execute($sql);

  5. #15
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Duplicate Sessions

    Quote Originally Posted by lat9 View Post
    lhungil pointed out a couple of posts back that it's most likely a race condition on busy stores (the check/optional insert is not atomic). Perhaps that section could be made atomic without changing the functionality as:
    Code:
     $expiry = time() + $SESS_LIFE;
     $sql = "insert IGNORE into " . TABLE_SESSIONS . "
               values ('" . zen_db_input($key) . "', '" . zen_db_input($expiry) . "', '" . zen_db_input($val) . "')";
    
     $db->Execute($sql);
    
     $sql = "update " . TABLE_SESSIONS . "
               set expiry = '" . zen_db_input($expiry) . "', value = '" . zen_db_input($val) . "'
               where sesskey = '" . zen_db_input($key) . "'";
    
     $result = $db->Execute($sql);
    Based on when this has been observed to occur, I would agree that it seems like a race condition that causes this. The above suggested code, would be expected to replace the section shown previously, correct? Not some sub-part of the various if this else that conditions?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #16
    Join Date
    Apr 2009
    Posts
    2,134
    Plugin Contributions
    3

    Default Re: Duplicate Sessions

    Well, yes, it evidently might be created by some kind of race condition. ( Off the record I am surprised by how often this is happening if that is the case just because of the probability of it but that just means that I am surprised not that I don't think it is so)

    Yes, that code might replace the existing code.

    @mc Yes, it would replace the code block that I pasted in its entirety.

    I may or may not give it a try. Trade off here is changing session handling code which would mean that I need to find the time to actively monitor the store after the change or living with a couple of errors a day.

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 5
    Last Post: 7 Mar 2015, 07:56 PM
  2. v153 PHP Fatal error: Duplicate entry for key insert into sessions
    By carlwhat in forum General Questions
    Replies: 2
    Last Post: 6 Jan 2015, 02:32 AM
  3. v151 Duplicate entry for key insert into sessions
    By RCwebdev in forum General Questions
    Replies: 12
    Last Post: 20 Aug 2013, 08:22 AM
  4. v151 Duplicate entry error on sessions table with new install on Mountain Lion Server
    By jeffmic in forum Installing on a Mac Server
    Replies: 4
    Last Post: 26 Mar 2013, 08:37 AM
  5. Duplicate entry in sessions table
    By fibre in forum Bug Reports
    Replies: 0
    Last Post: 11 Oct 2010, 06:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg